一、环境准备
1.1 主机信息
项目 | 内容 |
---|---|
操作系统 | CentOS7.6 |
IP | 192.168.4.201 |
主机名 | opgs201 |
CPU | 8core |
内存 | 16GB |
磁盘1 | 100GB |
1.2 操作系统准备
创建一个虚拟机
安装操作系统,选择带GUI的安装
1.3 准备安装环境
安装python3
安装python3,因为这个新装的centos7.6是没有自带python3的,这里我建议安装python3.6就够
先挂载光盘iso
##挂载虚拟机的光盘
mount /dev/cdrom /mnt
#备份原来的yum文件
cd /etc/yum.repos.d
mkdir bk
mv *.repo bk/
##创建一个repo
echo "[EL]" >> /etc/yum.repos.d/linux7.repo
echo "name =LINUX7.DVD" >> /etc/yum.repos.d/linux7.repo
echo "baseurl=file:///mnt" >> /etc/yum.repos.d/linux7.repo
echo "gpgcheck=0" >> /etc/yum.repos.d/linux7.repo
echo "enabled=1" >> /etc/yum.repos.d/linux7.repo
可以参考我的这篇文章,就是为了适配安装openGauss而安装python3的
https://www.cnblogs.com/su1999/p/18459499
检查软件依赖
安装好之后,安装下面openGauss需要的依赖包(有些在上面安装python3时安装了)
yum install -y lksctp*
yum install -y java-1.8.0-openjdk*
yum install -y psmisc
yum install -y bzip2
yum install -y libaio-devel
yum install -y flex bison ncurses-devel glibc-devel patch readline-devel redhat-lsb-core libnsl
配置hosts
echo "192.168.4.201 opgs201" >> /etc/hosts
关闭防火墙等配置
systemctl disable firewalld.service
systemctl stop firewalld.service
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
cat /etc/selinux/config|grep SELINUX=
修改字符集参数
echo "export LANG=en_US.UTF-8" >> /etc/profile
source /etc/profile
设置root用户远程登录
这里可以使用脚本快速完成
sed -i '/PermitRootLogin/s/^/#/' /etc/ssh/sshd_config
sed -i '/Banner/s/^/#/' /etc/ssh/sshd_config
echo -e "\n" >> /etc/ssh/sshd_config
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
echo "Banner none " >> /etc/ssh/sshd_config
systemctl restart sshd.service
设置时区与时间
在生产环境可以使用NTP或者chrony来同步服务器的时间
rm -rf /etc/localtime
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
关闭swap(可选)
关闭swap可以提升性能
sed -i '/swap/s/^/#/' /etc/fstab
cat /etc/fstab
swapoff -a
修改系统内核参数
cat >> /etc/sysctl.conf << EOF
net.ipv4.tcp_retries1 = 5
net.ipv4.tcp_syn_retries = 5
net.ipv4.tcp_fin_timeout = 60
EOF
sysctl -p
关闭透明页
临时关闭透明页
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
写进开机文件,永久生效
cat >> /etc/rc.d/rc.local <<EOF
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
EOF
##生效
chmod +x /etc/rc.d/rc.local
修改启动级别
这一步是可选的
systemctl set-default multi-user.target
一次性全部配置
yum install -y lksctp*
yum install -y java-1.8.0-openjdk*
yum install -y psmisc
yum install -y bzip2
yum install -y libaio-devel
yum install -y flex bison ncurses-devel glibc-devel patch readline-devel redhat-lsb-core libnsl
echo "192.168.4.201 opgs201" >> /etc/hosts
systemctl disable firewalld.service
systemctl stop firewalld.service
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
echo "export LANG=en_US.UTF-8" >> /etc/profile
source /etc/profile
sed -i '/PermitRootLogin/s/^/#/' /etc/ssh/sshd_config
sed -i '/Banner/s/^/#/' /etc/ssh/sshd_config
echo -e "\n" >> /etc/ssh/sshd_config
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
echo "Banner none " >> /etc/ssh/sshd_config
systemctl restart sshd.service
rm -rf /etc/localtime
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
sed -i '/swap/s/^/#/' /etc/fstab
swapoff -a
cat >> /etc/sysctl.conf << EOF
net.ipv4.tcp_retries1 = 5
net.ipv4.tcp_syn_retries = 5
net.ipv4.tcp_fin_timeout = 60
EOF
sysctl -p
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
cat >> /etc/rc.d/rc.local <<EOF
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
EOF
##生效
chmod +x /etc/rc.d/rc.local
systemctl set-default multi-user.target
echo -e "\n"
重启
reboot
二、安装openGauss5.0数据库
2.1 安装前准备
创建相关的目录与用户
这里先手动创建用户与组
groupadd dbgrp
useradd -g dbgrp omm
### 密码Gauss@1234 需要有一定的福再度
echo Gauss@1234 | passwd --stdin omm
创建目录
##放置软件包的目录
mkdir -p /opt/software/openGauss
chmod 755 -R /opt/software/openGauss
##openGauss数据库的目录,注意需要保持空目录,不然安装会错误
##
mkdir -p /openGauss/
chmod -R 755 /openGauss
chown -R omm:dbgrp /openGauss/
上传并解压安装包
把安装包上传到/opt/software/openGauss/目录下,解压
/opt/software/openGauss/
tar -zxvf openGauss-5.0.3-CentOS-64bit-all.tar.gz
tar -zxvf openGauss-5.0.3-CentOS-64bit-om.tar.gz
示例:
[root@opgs201 ~]# cd /opt/software/openGauss/
[root@opgs201 openGauss]# tar -zxvf openGauss-5.0.3-CentOS-64bit-all.tar.gz
openGauss-5.0.3-CentOS-64bit-cm.tar.gz
openGauss-5.0.3-CentOS-64bit-om.tar.gz
openGauss-5.0.3-CentOS-64bit.tar.bz2
openGauss-5.0.3-CentOS-64bit-cm.sha256
openGauss-5.0.3-CentOS-64bit-om.sha256
openGauss-5.0.3-CentOS-64bit.sha256
upgrade_sql.tar.gz
upgrade_sql.sha256
解压后有这些文件
[root@opgs201 soft]# ls -l
total 264712
-rw-r--r-- 1 root root 134969411 Oct 9 23:42 openGauss-5.0.3-CentOS-64bit-all.tar.gz
-rw-r--r-- 1 root root 105 Jul 31 21:15 openGauss-5.0.3-CentOS-64bit-cm.sha256
-rw-r--r-- 1 root root 22528084 Jul 31 21:15 openGauss-5.0.3-CentOS-64bit-cm.tar.gz
-rw-r--r-- 1 root root 65 Jul 31 21:14 openGauss-5.0.3-CentOS-64bit-om.sha256
-rw-r--r-- 1 root root 11973852 Jul 31 21:14 openGauss-5.0.3-CentOS-64bit-om.tar.gz
-rw-r--r-- 1 root root 65 Jul 31 21:15 openGauss-5.0.3-CentOS-64bit.sha256
-rw-r--r-- 1 root root 101064032 Jul 31 21:15 openGauss-5.0.3-CentOS-64bit.tar.bz2
-rw------- 1 root root 65 Jul 31 21:13 upgrade_sql.sha256
-rw------- 1 root root 502230 Jul 31 21:13 upgrade_sql.tar.gz
再解压里面的这个
[root@opgs201 openGauss]# tar -zxvf openGauss-5.0.3-CentOS-64bit-om.tar.gz
准备XML文件
我这个是单节点的,所以准备单节点的xml,这个文件配在哪里呢?
配在软件目录下
cd /opt/software/openGauss/
vi cluster_config.xml
或者直接cat
cat >> /opt/software/openGauss/cluster_config.xml << EOF
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<CLUSTER>
<PARAM name="clusterName" value="dbCluster" />
<!-- 这里输入自己的主机名 -->
<PARAM name="nodeNames" value="opgs201" />
<!-- 数据库安装目录-->
<PARAM name="gaussdbAppPath" value="/openGauss/app" />
<!-- 日志目录-->
<PARAM name="gaussdbLogPath" value="/openGauss/log/omm" />
<!-- 临时文件目录-->
<PARAM name="tmpMppdbPath" value="/openGauss/tmp" />
<!-- 数据库工具目录-->
<PARAM name="gaussdbToolPath" value="/openGauss/om" />
<!-- 数据库core文件目录-->
<PARAM name="corePath" value="/openGauss/corefile" />
<!-- 节点IP,与数据库节点名称列表一一对应 -->
<PARAM name="backIp1s" value="192.168.4.201"/>
</CLUSTER>
<!-- 每台服务器上的节点部署信息 -->
<DEVICELIST>
<!-- 节点1上的部署信息 -->
<DEVICE sn="node1_hostname">
<!-- 节点1的主机名称 -->
<PARAM name="name" value="opgs201"/>
<!-- 节点1所在的AZ及AZ优先级 -->
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<!-- 节点1的IP,如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
<PARAM name="backIp1" value="192.168.4.201"/>
<PARAM name="sshIp1" value="192.168.4.201"/>
<!--dbnode-->
<PARAM name="dataNum" value="1"/>
<PARAM name="dataPortBase" value="15400"/>
<PARAM name="dataNode1" value="/openGauss/data/dn"/>
<PARAM name="dataNode1_syncNum" value="0"/>
</DEVICE>
</DEVICELIST>
</ROOT>
EOF
看看这个
2.2 安装openGauss数据库
执行preinstall
进入script目录
里面有很多脚本
[root@opgs201 soft]# cd script/
[root@opgs201 script]# ./gs
gs_backup gs_checkperf gs_expansion gs_postuninstall gs_sdr gs_uninstall
gs_check gs_collector gs_install gs_preinstall gs_ssh gs_upgradectl
gs_checkos gs_dropnode gs_om gspylib/ gs_sshexkey
[root@opgs201 script]# ls
base_diff gs_check gs_expansion gspylib gs_upgradectl os_platform ssh-agent
base_utils gs_checkos gs_install gs_sdr impl py_pstree.py ssh-copy-id
config gs_checkperf gs_om gs_ssh __init__.py scp ssh-keygen
domain_utils gs_collector gs_postuninstall gs_sshexkey killall ssh transfer.py
gs_backup gs_dropnode gs_preinstall gs_uninstall local ssh-add
执行其中的gs_preinstall检查脚本
[root@opgs201 script]# ./gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/cluster_config.xml
Parsing the configuration file.
Successfully parsed the configuration file.
Installing the tools on the local node.
Successfully installed the tools on the local node.
Setting host ip env
Successfully set host ip env.
Are you sure you want to create the user[omm] (yes/no)? yes
Preparing SSH service.
Successfully prepared SSH service.
Checking OS software.
Successfully check os software.
Checking OS version.
Successfully checked OS version.
Creating cluster's path.
Successfully created cluster's path.
Set and check OS parameter.
Setting OS parameters.
Successfully set OS parameters.
Warning: Installation environment contains some warning messages.
Please get more details by "/opt/software/openGauss/script/gs_checkos -i A -h opgs201 --detail".
Set and check OS parameter completed.
Preparing CRON service.
Successfully prepared CRON service.
Setting user environmental variables.
Successfully set user environmental variables.
Setting the dynamic link library.
Successfully set the dynamic link library.
Setting Core file
Successfully set core path.
Setting pssh path
Successfully set pssh path.
Setting Cgroup.
Successfully set Cgroup.
Set ARM Optimization.
No need to set ARM Optimization.
Fixing server package owner.
Setting finish flag.
Successfully set finish flag.
Preinstallation succeeded.
[root@opgs201 script]#
使用omm用户执行安装
现在有了omm用户了,程序会写进一下环境变量
[root@opgs201 script]# su - omm
Last login: Sun Oct 13 08:45:28 CST 2024
[omm@opgs201 ~]$ cat .bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
export GPHOME=/openGauss/om
export PATH=$GPHOME/script/gspylib/pssh/bin:$GPHOME/script:$PATH
export LD_LIBRARY_PATH=$GPHOME/lib:$LD_LIBRARY_PATH
export PYTHONPATH=$GPHOME/lib
export GAUSSHOME=/openGauss/app
export PATH=$GAUSSHOME/bin:$PATH
export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH
export S3_CLIENT_CRT_FILE=$GAUSSHOME/lib/client.crt
export GAUSS_VERSION=5.0.3
export PGHOST=/openGauss/tmp
export GAUSSLOG=/openGauss/log/omm/omm
umask 077
export GAUSS_ENV=1
使用omm用户安装
[omm@opgs201 ~]$ gs_install -X /opt/software/openGauss/cluster_config.xml
Parsing the configuration file.
Check preinstall on every node.
Successfully checked preinstall on every node.
Creating the backup directory.
Successfully created the backup directory.
begin deploy..
Installing the cluster.
begin prepare Install Cluster..
Checking the installation environment on all nodes.
begin install Cluster..
Installing applications on all nodes.
Successfully installed APP.
begin init Instance..
encrypt cipher and rand files for database.
Please enter password for database:
Please repeat for database:
begin to create CA cert files
The sslcert will be generated in /openGauss/app/share/sslcert/om
NO cm_server instance, no need to create CA for CM.
Non-dss_ssl_enable, no need to create CA for DSS
Cluster installation is completed.
Configuring.
Deleting instances from all nodes.
Successfully deleted instances from all nodes.
Checking node configuration on all nodes.
Initializing instances on all nodes.
Updating instance configuration on all nodes.
Check consistence of memCheck and coresCheck on database nodes.
Configuring pg_hba on all nodes.
Configuration is completed.
The cluster status is Normal.
Successfully started cluster.
Successfully installed application.
end deploy..
2.3 安装后检查
echo "export PGDATABASE=postgres" >> ~/.bashrc、
echo "export PGDATA=/openGauss/data/dn" >> ~/.bashrc
echo "export PGPORT=15400" >> ~/.bashrc
echo "alias gsql='gsql -r'" >> ~/.bashrc
echo "alias dba='gsql -d postgres -p 15400'" >> ~/.bashrc
source ~/.bash_profile
执行gsql命令就能进去了
[omm@opgs201 ~]$ dba
gsql ((openGauss 5.0.3 build 89d144c2) compiled at 2024-07-31 20:59:31 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
openGauss=# select version();
version
---------------------------------------------------------------------------------------------------------------------------------------
---------------
(openGauss 5.0.3 build 89d144c2) compiled at 2024-07-31 20:59:31 commit 0 last mr on x86_64-unknown-linux-gnu, compiled by g++ (GCC)
7.3.0, 64-bit
(1 row)
2.4 数据库的简单管理
启停数据库
停止
[omm@opgs201 ~]$ gs_om -t stop
Stopping cluster.
=========================================
Successfully stopped cluster.
=========================================
End stop cluster.
标签:openGauss5.0,gs,Successfully,教程,echo,etc,openGauss,root,CentOS7.6
From: https://www.cnblogs.com/su1999/p/18464707