一、前言
GBase 8c 是 GBASE公司(天津南大通用数据技术股份有限公司)自主研发的一款多模多态的企业级分布式数据库:支持行存、列存、内存等多种存储模式;支持单机、主备式、分布式等多种部署形态。
GBase 8c 具备高性能、高可用、弹性伸缩、高安全性等特性,可以部署在物理机、虚拟机、容器、私有云和公有云,为关键行业核心系统、互联网业务系统和政企业务系统提供安全、稳定、可靠的数据存储和管理服务。
本文讲解集群版安装部署步骤、卸载、连接测试。属于入门级别的实操课程。
二、环境准备
0、标识符约定:
命令前的 # 表示以 root 账户执行;
命令前的 $ 表示以 DBA 账户执行。
1、操作系统
硬件 | 配置 |
---|---|
CPU | Intel® Xeon® CPU E5-2699 v3 @ 2.30GHz |
Memory | 16G |
Disk | SSD 50G |
2、集群配置(三个节点):
IP | 角色 |
---|---|
10.168.10.70 | gha_server(高可用服务)、dcs(分布式配置存储)、gtm(全局事务管理)、coordinator(协调器)、datanode(主数据节点) |
10.168.10.71 | datanode1(备数据节点) |
10.168.10.72 | datanode2(备数据节点) |
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) 每个节点执行
# sestatus
如果系统提示以下信息说明 selinux 已被禁用
SELinux status: disabled
(2) 否则,打开每个节点的 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 文件中
192.168.10.70 gbase8c_1
192.168.10.71 gbase8c_2
192.168.10.72 gbase8c_3
7、配置系统内核参数
【目的】避免信号量不足无法初始化。
【现象】如果信号量不足,执行安装脚本会发现以下错误
[step 1]: check parameter
[step 2]: check install env and os setting
On systemwide basis, the maximum number of SEMMNI is not correct. the current SEMMNI value is: 128. Please check it.
The required value should be greater than 321. You can modify it in file '/etc/sysctl.conf'.
$ sudo vim /etc/sysctl.conf
在sysctl.conf 配置文件中,配置参数如下:
kernel.sem = 40960 2048000 40960 20480
保存并退出。执行 sysctl -p 生效。
三、集群安装
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 账户下安装的。
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
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 192.168.10.70 nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1
# Hosts on local network are less restricted.
#restrict 192.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 192.168.10.71 nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1
# Hosts on local network are less restricted.
#restrict 192.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 192.168.10.70
Fudge 192.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 192.168.10.72 nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1
# Hosts on local network are less restricted.
#restrict 192.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 192.168.10.70
Fudge 192.168.10.70 stratum 10
ntp.conf 文件存盘退出后,执行
$ sudo service ntpd start # 启动NTP服务
$ sudo chkconfig ntpd on # 设置 NTP 服务开机自启
5、使用 SSH 工具上传安装包(GBase8cV5_S3.0.0B37_centos7.8_x86_64.tar.gz)到主安装节点(10.168.10.70) /home/gbase/gbase8c_pkg 下
6、解压安装包
$ cd /home/gbase/gbase8c_pkg
$ tar xvf GBase8cV5_S3.0.0B37_centos7.8_x86_64.tar.gz
解压成功新增四个文件
GBase8cV5_S3.0.0B37_CentOS_x86_64_om.sha256
GBase8cV5_S3.0.0B37_CentOS_x86_64_om.tar.gz
GBase8cV5_S3.0.0B37_CentOS_x86_64_pgpool.tar.gz
GBase8cV5_S3.0.0B37_CentOS_x86_64.sha256
GBase8cV5_S3.0.0B37_CentOS_x86_64.tar.bz2
再次解压
$ tar xvf GBase8cV5_S3.0.0B37_CentOS_x86_64_om.tar.gz
7、开始安装
(1) 编辑集群部署文件 gbase8c.yml:
[10.168.10.70]$ cp /home/gbase/gbase8c_pkg/gbase8c.yml /home/gbase
[10.168.10.70]$ vi /home/gbase/gbase8c.yml
修改如下——
gha_server:
- gha_server1:
host: 10.168.10.70
port: 20001
dcs:
- host: 10.168.10.70
port: 2379
gtm:
- gtm1:
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
role: primary
port: 5432
agent_port: 8003
work_dir: /home/gbase/data/coord/cn1
datanode:
- dn1:
- dn1_1:
host: 10.168.10.71
role: primary
port: 15432
agent_port: 8005
work_dir: /home/gbase/data/dn1/dn1_1
- dn1_2:
host: 10.168.10.71
role: standby
port: 15433
agent_port: 8006
work_dir: /home/gbase/data/dn1/dn1_2
- dn1_3:
host: 10.168.10.72
role: standby
port: 15433
agent_port: 8006
work_dir: /home/gbase/data/dn1/dn1_3
env:
# cluster_type allowed values: multiple-nodes, single-inst, default is multiple-nodes
cluster_type: single-inst
pkg_path: /home/gbase/gbase8c_pkg/
prefix: /home/gbase/deploy
version: V5_S3.0.0B37
user: gbase
port: 22
# encryption_type: aes
# encryption_passwd: fce06e206932e9e930f96c63b28cf951
(2) 执行安装脚本:
[10.168.10.70]$ /home/gbase/script/gha_ctl install -p /home/gbase/
A. 数据库名称缺省 gbase8c,如果需要更名可以使用 -c 参数;
B. 配置文件路径缺省为 /home/gbase,如果需要更改可以使用 -p 参数。
执行时间 3+ 分钟,安装结束后,脚本会提示
{
"ret":0,
"msg":"Success"
}
集群安装成功!
(3) 节点状态检查
执行
[10.168.10.70]$ /home/gbase/script/gha_ctl monitor -l http://10.168.10.70:2379
结果如下,说明集群安装正常,数据服务启动中
{
"cluster": "gbase8c",
"version": "V5_S3.0.0B28",
"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]$ /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)执行
$ /home/gbase/script/gha_ctl uninstall -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)