CA02.GBase 8c V5 分布式集群版安装示例

一、前言

        GBase 8c 是 GBASE公司(天津南大通用数据技术股份有限公司)自主研发的一款多模多态的企业级分布式数据库:支持行存、列存、内存等多种存储模式;支持单机、主备式、分布式等多种部署形态。
        GBase 8c 具备高性能、高可用、弹性伸缩、高安全性等特性,可以部署在物理机、虚拟机、容器、私有云和公有云,为关键行业核心系统、互联网业务系统和政企业务系统提供安全、稳定、可靠的数据存储和管理服务。
        本文讲解集群版安装部署步骤、卸载、连接测试。属于入门级别的实操课程。

二、环境准备

0、标识符约定:
命令前的 # 表示以 root 账户执行;
命令前的 $ 表示以 DBA 账户执行。

1、节点软硬件配置

硬件配置
CPUIntel® Xeon® CPU E5-2699 v3 @ 2.30GHz
Memory8G
DiskSSD 50G
操作系统
CentOS Linux release 7.9.2009 (Core)

针对内存 4G 的节点,需要增加 8G SWAP 才能安装成功。具体步骤:

① 创建 8G 的 Swap 文件
# dd if=/dev/zero of=/etc/swapfile bs=1024 count=8192000
② 制作为 Swap 文件
# mkswap /etc/swapfile
③ 令 Swap 文件生效
# swapon /etc/swapfile
④ 查看当前SWAP
# swapon -s

文件名				类型		大小	已用	权限
/dev/dm-1                              	partition	1048572	59840	-2
/etc/swapfile                          	file	8191996	3148	-3

⑤ 自动挂载
编辑/etc/fstab,将以下行追加到文件末尾
/etc/swapfile swap swap defaults 0 0

# vi /etc/fstab
/dev/vda1 / ext3 noatime,acl,user_xattr 1 1
proc /proc proc defaults 0 0
sysfs /sys sysfs noauto 0 0
debugfs /sys/kernel/debug debugfs noauto 0 0
devpts /dev/pts devpts mode=0620,gid=5 0 0
/etc/swapfile swap swap defaults 0 0

⑥ 查看创建好的 SWAP,已经增长了 8G
# free -m

              total        used        free      shared  buff/cache   available
Mem:           3770        1660         117        1740        1992         138
Swap:          9023          61        8962

2、集群服务配置(三个节点):

IP角色
10.168.10.70gha_server(高可用服务)、dcs(分布式配置存储)、gtm(全局事务管理)、coordinator(协调器)
10.168.10.71datanode1(数据节点)、dcs(分布式配置存储)
10.168.10.72datanode2(数据节点)、dcs(分布式配置存储)

3、确保集群每个节点的防火墙是关闭的
(1) 检查每个节点的防火墙状态
# systemctl status firewalld.service
如果系统提示以下信息说明防火墙已被禁用

● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

(2) 如果防火墙没有关闭,则执行
# systemctl stop firewalld.service
# systemctl disable firewalld.service
以上两条命令关闭防火墙并禁止防火墙开机自启动。

4、确保每个节点的 SELINUX 是关闭的
(1) 检查每个节点的 SELINUX 状态
# sestatus
如果系统提示以下信息说明 selinux 已被禁用

SELinux status:                 disabled

(2) 如果 SELINUX 没有关闭,需要编辑当前节点的 selinux 配置文件
# vi /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

将 SELINUX 关键字的值修改为 disabled,存盘退出,执行
# shutdown -r
重启操作系统。

5、规范三个节点的主机名
[10.168.10.70]# hostnamectl set-hostname gbase8c_1
[10.168.10.71]# hostnamectl set-hostname gbase8c_2
[10.168.10.72]# hostnamectl set-hostname gbase8c_3

6、配置三个节点的 IP 主机名映射:
编辑三个节点的 hosts 文件
# vi /etc/hosts
将以下三行信息追加到 hosts 文件中

10.168.10.70	gbase8c_1
10.168.10.71	gbase8c_2
10.168.10.72	gbase8c_3
三、集群安装

1、每个节点都要创建 DBA 用户
# useradd gbase
# passwd gbase

2、添加gbase 用户至sudoer 列表
三个节点都要执行如下操作——
# visudo
打开 sudoer 配置文件,找到 “root ALL=(ALL) ALL” 行,在下方增加
“gbase ALL=(ALL) NOPASSWD:ALL”

## Allow root to run any commands anywhere
root ALL=(ALL) ALL
gbase ALL=(ALL) NOPASSWD:ALL

完成 sudoer 配置后,数据库安装就可以用 gbase 用户了。本文使用的安装包是不能在 root 账户下安装的。

个别操作系统,经过以上的设置后,gbase 用户执行 sudo 命令时,第一次还是有密码提示。需要有以下补救措施:

(1) root 账户下进入 /etc/sudoers.d/ 目录
# cd /etc/sudoers.d/
(2) 生成新文件 gbase:
# vi gbase
添加如下信息后,存盘即可:

gbase ALL=(ALL) NOPASSWD:ALL

3、配置gbase用户ssh互信:
每个节点都要执行以下命令——
(1) 切换到 gbase 用户下
# su - gbase
(2) 创建秘钥目录和必要的授权
$ mkdir ~/.ssh
$ chmod 700 ~/.ssh
(3) 生成秘钥文件(连续回车即可)
$ ssh-keygen -t rsa
(4) 将公钥文件上传至其他节点即可实现免密登录:
此操作需输入 gbase 的密码,所有节点都要执行——
$ ssh-copy-id gbase@10.168.10.70
$ ssh-copy-id gbase@10.168.10.71
$ ssh-copy-id gbase@10.168.10.72
$ echo 'StrictHostKeyChecking no' >> ~/.ssh/config; echo 'UserKnownHostsFile ~/.ssh/known_hosts' >> ~/.ssh/config; chmod 644 ~/.ssh/config
(5) 检查是否已实现互信免密:
在主安装节点(10.168.10.70)上执行:
$ ssh -E /dev/null -p 22 gbase@10.168.10.70 "hostname"
$ ssh -E /dev/null -p 22 gbase@10.168.10.71 "hostname"
$ ssh -E /dev/null -p 22 gbase@10.168.10.72 "hostname"
如果不需要输入密码即能显示主机名,则表明互信配置成功!

4、配置系统时间同步
(1) 主安装节点(10.168.10.70)作为 server
执行
$ vi /etc/ntp.conf
打开 NTP 服务配置文件,修改如下:

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 10.168.10.70 nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1

# Hosts on local network are less restricted.
#restrict 10.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 127.127.1.0
Fudge 127.127.1.0 stratum 10

ntp.conf 文件存盘退出后,执行
$ sudo service ntpd start # 启动NTP服务
$ sudo chkconfig ntpd on # 设置 NTP 服务开机自启

(2) 修改数据节点一(10.168.10.71)NTP 配置
执行
$ vi /etc/ntp.conf
打开 NTP 服务配置文件,修改如下:

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 10.168.10.71 nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1

# Hosts on local network are less restricted.
#restrict 10.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 10.168.10.70
Fudge 10.168.10.70 stratum 10

ntp.conf 文件存盘退出后,执行
$ sudo service ntpd start # 启动NTP服务
$ sudo chkconfig ntpd on # 设置 NTP 服务开机自启

(3) 修改数据节点二(10.168.10.72)NTP 配置
执行
$ vi /etc/ntp.conf
打开 NTP 服务配置文件,修改如下:

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 10.168.10.72 nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1

# Hosts on local network are less restricted.
#restrict 10.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 10.168.10.70
Fudge 10.168.10.70 stratum 10

ntp.conf 文件存盘退出后,执行
$ sudo service ntpd start # 启动NTP服务
$ sudo chkconfig ntpd on # 设置 NTP 服务开机自启

5、上传安装包:
[10.168.10.70]$ cd /home/gbase
[10.168.10.70]$ mkdir gbase_package
最后使用 SSH 工具上传(GBase8cV5_S3.0.0B78_centos7.8_x86_64.tar.gz)到主安装节点(10.168.10.70) /home/gbase/gbase_package 下。

6、解压安装包
$ cd /home/gbase/gbase_package
$ sudo tar xvf GBase8cV5_S3.0.0B78_centos7.8_x86_64.tar.gz
解压成功新增五个文件

GBase8cV5_S3.0.0B78_CentOS_x86_64_om.sha256
GBase8cV5_S3.0.0B78_CentOS_x86_64_om.tar.gz
GBase8cV5_S3.0.0B78_CentOS_x86_64_pgpool.tar.gz
GBase8cV5_S3.0.0B78_CentOS_x86_64.sha256
GBase8cV5_S3.0.0B78_CentOS_x86_64.tar.bz2

再次解压
$ sudo tar xvf GBase8cV5_S3.0.0B78_CentOS_x86_64_om.tar.gz

7、开始安装
(1) 编辑集群部署文件 gbase8c.yml:
[10.168.10.70]$ vi /home/gbase/gbase_package/gbase.yml
修改如下——

gha_server:
  - gha_server1:
      host: 10.168.10.70
      port: 20001
dcs:
  - host: 10.168.10.70
    port: 2379
  - host: 10.168.10.71
    port: 2379
  - host: 10.168.10.72
    port: 2379
gtm:
  - gtm1:
      host: 10.168.10.70
      agent_host: 10.168.10.70
      role: primary
      port: 6666
      agent_port: 8001
      work_dir: /home/gbase/data/gtm/gtm1

coordinator:
  - cn1:
      host: 10.168.10.70
      agent_host: 10.168.10.70
      role: primary
      port: 5432
      agent_port: 8003
      work_dir: /home/gbase/data/coord/cn1
datanode:
  - dn1:
      - dn1_1:
          host: 10.168.10.71
          agent_host: 10.168.10.71
          role: primary
          port: 15432
          agent_port: 8005
          work_dir: /home/gbase/data/dn1/dn1_1
  - dn2:
      - dn2_1:
          host: 10.168.10.72
          agent_host: 10.168.10.72
          role: primary
          port: 20010
          agent_port: 8007
          work_dir: /home/gbase/data/dn2/dn2_1
env:
  # cluster_type allowed values: multiple-nodes, single-inst, default is multiple-nodes
  cluster_type: multiple-nodes
  pkg_path: /home/gbase/gbase_package # 安装包所在目录
  prefix: /home/gbase/gbase_db # 运行目录
  version: V5_S3.0.0B78
  user: gbase
  port: 22
# constant:
#  virtual_ip: 100.0.1.254/24

(2) 执行安装脚本:
[10.168.10.70]$ cd /home/gbase/gbase_package/script
[10.168.10.70]$ ./gha_ctl install -c gbase -p /home/gbase/gbase_package

A. -c 参数:数据库名称,缺省 gbase;
B. -p 参数:配置文件路径,缺省 /home/gbase。

执行时间 3+ 分钟,安装结束后,脚本会提示

{
    "ret":0,
    "msg":"Success"
}

集群安装成功!

异常处理
在没有安装开发组件的操作系统上,执行安装脚本可能出现以下现象:

{
    "ret":-1,
    "msg":"Host localhost install or upgrade dependency {'libaio': None} failed!  Host 172.168.10.227 install or upgrade dependency {'libaio': None} failed!  Host 172.168.10.108 install or upgrade dependency {'libaio': None} failed!  "
}

——解决:
在集群所有节点安装 libaio 组件
[10.168.10.70]# yum -y install libaio
[10.168.10.71]# yum -y install libaio
[10.168.10.72]# yum -y install libaio

(3) 节点状态检查
在主安装节点上执行
[10.168.10.70]$ exit
[10.168.10.70]# su - gbase

以上两个命令是保证环境变量生效

[10.168.10.70]$ gha_ctl monitor -l http://10.168.10.70:2379
结果如下,说明集群安装正常,数据服务启动中

{
    "cluster": "gbase",
    "version": "V5_S3.0.0B78",
    "server": [
        {
            "name": "gha_server1",
            "host": "10.168.10.70",
            "port": "20001",
            "state": "running",
            "isLeader": true
        }
    ],
    "gtm": [
        {
            "name": "gtm1",
            "host": "10.168.10.70",
            "port": "6666",
            "workDir": "/home/gbase/data/gtm/gtm1",
            "agentPort": "8001",
            "state": "running",
            "role": "primary"
        }
    ],
    "coordinator": [
        {
            "name": "cn1",
            "host": "10.168.10.70",
            "port": "5432",
            "workDir": "/home/gbase/data/coord/cn1",
            "agentPort": "8003",
            "state": "running",
            "role": "primary",
            "central": true
        }
    ],
    "datanode": {
        "dn1": [
            {
                "name": "dn1_1",
                "host": "10.168.10.71",
                "port": "15432",
                "workDir": "/home/gbase/data/dn1/dn1_1",
                "agentPort": "8005",
                "state": "running",
                "role": "primary"
            }
        ],
        "dn2": [
            {
                "name": "dn2_1",
                "host": "10.168.10.72",
                "port": "20010",
                "workDir": "/home/gbase/data/dn2/dn2_1",
                "agentPort": "8007",
                "state": "running",
                "role": "primary"
            }
        ]
    },
    "dcs": {
        "clusterState": "healthy",
        "members": [
            {
                "url": "http://10.168.10.71:2379",
                "id": "47d645d70d059264",
                "name": "node_1",
                "isLeader": false,
                "state": "healthy"
            },
            {
                "url": "http://10.168.10.70:2379",
                "id": "742a6fd575a41be4",
                "name": "node_0",
                "isLeader": true,
                "state": "healthy"
            },
            {
                "url": "http://10.168.10.72:2379",
                "id": "9e108bbe22487cc7",
                "name": "node_2",
                "isLeader": false,
                "state": "healthy"
            }
        ]
    }
}

也可以执行
[10.168.10.70]$ gha_ctl monitor -l http://10.168.10.70:2379 -H

+----+-------------+--------------+-------+---------+--------+
| No |     name    |     host     |  port |  state  | leader |
+----+-------------+--------------+-------+---------+--------+
| 0  | gha_server1 | 10.168.10.70 | 20001 | running |  True  |
+----+-------------+--------------+-------+---------+--------+
+----+------+--------------+------+---------------------------+---------+---------+
| No | name |     host     | port |          work_dir         |  state  |   role  |
+----+------+--------------+------+---------------------------+---------+---------+
| 0  | gtm1 | 10.168.10.70 | 6666 | /home/gbase/data/gtm/gtm1 | running | primary |
+----+------+--------------+------+---------------------------+---------+---------+
+----+------+--------------+------+----------------------------+---------+---------+
| No | name |     host     | port |          work_dir          |  state  |   role  |
+----+------+--------------+------+----------------------------+---------+---------+
| 0  | cn1  | 10.168.10.70 | 5432 | /home/gbase/data/coord/cn1 | running | primary |
+----+------+--------------+------+----------------------------+---------+---------+
+----+-------+-------+--------------+-------+----------------------------+---------+---------+
| No | group |  name |     host     |  port |          work_dir          |  state  |   role  |
+----+-------+-------+--------------+-------+----------------------------+---------+---------+
| 0  |  dn1  | dn1_1 | 10.168.10.71 | 15432 | /home/gbase/data/dn1/dn1_1 | running | primary |
| 1  |  dn2  | dn2_1 | 10.168.10.72 | 20010 | /home/gbase/data/dn2/dn2_1 | running | primary |
+----+-------+-------+--------------+-------+----------------------------+---------+---------+
+----+--------------------------+--------+---------+----------+
| No |           url            |  name  |  state  | isLeader |
+----+--------------------------+--------+---------+----------+
| 0  | http://10.168.10.70:2379 | node_0 | healthy |  False   |
| 1  | http://10.168.10.72:2379 | node_1 | healthy |   True   |
+----+--------------------------+--------+---------+----------+
四、数据库启停

停止数据库服务
[10.168.10.70]$ /home/gbase/script/gha_ctl stop all -l http://10.168.10.70:2379
启动数据库服务
[10.168.10.70]$ /home/gbase/script/gha_ctl start all -l http://10.168.10.70:2379

五、卸载

在主节点(10.168.10.70)执行以下命令——
1、停止所有节点的集群服务
$ gha_ctl stop all -l http://10.168.10.70:2379
2、集群程序的卸载:
$ gha_ctl uninstall -l http://10.168.10.70:2379
3、移除 dcs 集群:
$ cd /home/gbase/script
$ ./gha_ctl destroy dcs -l http://10.168.10.70:2379

六、连接和 SQL 测试

在主节点(10.168.10.70)执行
$ gsql -d postgres -p 5432
出现 postgres=# 操作符说明客户端工具 gsql 成功连接 8c 数据库
postgres=# create database testdb;
CREATE DATABASE
postgres=# create table student(ID int, Name varchar(10));
CREATE TABLE
postgres=# insert into student values(1, 'Mike'),(2,'John');
INSERT 0 2
postgres=# select * from student;
id | name
----±-----
1 | Mike
2 | John
(2 rows)

七、常见问题与解决:

       请参考 GBase 8c 安装过程中常见的问题与解决方法

  • 4
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值