Greenplum搭建与使用

Greenplum简介
       Greenplum是一个关系型数据库集群,由数个独立的数据库服务组合成的逻辑数据库,采用Shared-Nothing架构,整个集群由很多个数据节点(Segment Host)和控制节点(Master Host)组成,其中每个数据节点上可以运行多个数据库。简单来说,Shared-Nothing是一个分布式的架构,每个节点相对独立。在典型的Shared-Nothing中,每一个节点上所有的资源(CPU,内存,磁盘)都是独立的,每个节点都只有全部数据的一部分,也只能使用本节点的资源。
在Greenplum中,需要存储的数据在进入数据库时,将先进行数据分布的处理工作,将一个表中的数据平均分布到每个节点上,并为每个表指定一个分发列(distribute Column),之后便根据Hash来分布数据。基于Shared-Nothing的原则,Greenplum这样处理可以充分发挥每个节点处I/O的处理能力。在这一过程中,控制节点(Master Host)将不再承担计算任务,而只负责必要的逻辑控制和客户端交互。I/O瓶颈的解决为并行计算能力的提升创造了良好的环境,所有节点服务器组成一个强大的计算平台,实现快速的海量并行运算。Greenplum在数据仓库、商业智能的应用上,尤其是在海量数据的处理方面性能极其优异。
在这里插入图片描述

环境说明
Greenplum : 6.0.0-alpha.0+dev.13344.g4598f7c build dev-oss
CentOS7 : 7.6.1810
Python : 2.7.5

系统配置
一个Greenplum集群由一台Master和数台Segment组成,Master存储集群所有的元数据,所有的数据文件存放在Segment中,此处使用3台机器的规模(1Master,2Segment,我这边是机器有限,一般是1Master,3Segment),IP地址(根据读者的实际机器ip来填写)如下:
gp-master(8G+500G with CentOS7) 192.168.100.94
gp-sdw1(8G+500G with CentOS7) 192.168.100.95
gp-sdw2(8G+500G with CentOS7) 192.168.100.96

搭建步骤
安装环境准备
1.修改host文件
打开文件:vi /etc/hosts
输入各个节点修改成相应的名称,分别为gp-master, gp-sdw1, gp-sdw2
192.168.100.94 gp-master
192.168.100.95 gp-sdw1
192.168.100.96 gp-sdw2

2.复制到子节点

配置了主节点文件之后复制到其余子节点

scp /etc/hosts gp-sdw1:/etc

3.依次修改各个节点/etc/sysconfig/network文件

同时修改各个子节点和主节点 /etc/sysconfig/network这个文件如下(这个不同节点配置不一样,无法复制,所有机器都要修改)

[root@ gp-master ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME= gp-maste

这里的HOSTNAME一定要与/etc/hosts中的主机名一致,最终可以使用ping gp-sdw1节点名称命令测试是否配置好了
4.修改系统内核/etc/sysctl.conf文件

(说明:相同的配置先在主节点节点上配置,配置完成后在本节第八步中复制到其它节点上)

vi /etc/sysctl.conf
 
kernel.shmmni = 4096
kernel.shmall = 4000000000
kernel.sem = 250 512000 100 2048
kernel.sysrq = 1
kernel.core_uses_pid = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.msgmni = 2048
net.ipv4.tcp_syncookies = 1
net.ipv4.ip_forward = 0
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_syn_backlog = 4096
net.ipv4.conf.defalut.arp_filter = 1
net.ipv4.ip_local_port_range = 1025 65535
net.core.netdev_max_backlog = 10000
net.core.rmem_max = 2097152
net.core.wmem_max = 2097152
vm.overcommit_memory = 2     ### 测试环境要取消这个,否则oracle启不来 ### 值为1

最后让配置生效

[root@dw-greenplum-1~]# sysctl -p(让配置生效)

5.修改进程数/etc/security/limits.d/90-nproc.conf文件

(说明:相同的配置先在主节点节点上配置,配置完成后在本节第八步中复制到其它节点上)

vi /etc/security/limits.d/90-nproc.conf
*          soft    nproc     131072
root       soft    nproc     unlimited

6.修改/etc/selinux/config文件

(说明:相同的配置先在主节点节点上配置,配置完成后在本节第八步中复制到其它节点上)
每个结点执行如下操作
systemctl stop firewalld
systemctl disable firewalld

除此之外:

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=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

7.复制主节点配置到子节点

依次复制到各个子节点

scp /etc/sysctl.conf gp-sdw1:/etc
scp /etc/security/limits.d/90-nproc.conf gp-sdw1:/etc/security/limits.d
scp /etc/selinux/config gp-sdw1:/etc/selinux
  1. 创建gpadmin用户(所有节点)

    groupadd -g 530 gpadmin
    useradd -g 530 -u 530 -m -d /home/gpadmin -s /bin/bash gpadmin
    chown -R gpadmin:gpadmin /home/gpadmin
    echo “gpadmin” | passwd --stdin gpadmin

安装Greenplum DB
1.在Master节点上安装Greenplum DB

安装包是rpm格式的执行rpm安装命令:

rpm -ivh greenplum-db-5.16.0-rhel6-x86_64.rpm

默认的安装路径是/usr/local,然后需要修改该路径gpadmin操作权限:

chown -R gpadmin:gpadmin /usr/local

2.创建配置集群hostlist文件,打通节点
2.1 创建一个hostlist,包含所有节点主机名:

su - gpadmin
mkdir -p /home/gpadmin/conf
vi /home/gpadmin/conf/hostlist
 
gp-master
gp-sdw1
gp-sdw2

2.2 创建一个 seg_hosts ,包含所有的Segment Host的主机名:

vi /home/gpadmin/conf/seg_hosts
 
gp-sdw1
gp-sdw2

2.3 配置ssh免密连接:

[root@ gp-master ~]# su - gpadmin
[gpadmin@ gp-master ~]# source /usr/local/greenplum-db/greenplum_path.sh  
[gpadmin@ gp-master ~]# gpssh-exkeys -f /home/gpadmin/conf/hostlist
 
[STEP 1 of 5] create local ID and authorize on local host
  ... /home/gpadmin/.ssh/id_rsa file exists ... key generation skipped
 
[STEP 2 of 5] keyscan all hosts and update known_hosts file
 
[STEP 3 of 5] authorize current user on remote hosts
  ... send to gp-sdw1
  ... send to gp-sdw2
#提示:这里提示输入各个子节点gpadmin用户密码
[STEP 4 of 5] determine common authentication file content
 
[STEP 5 of 5] copy authentication files to all remote hosts
  ... finished key exchange with gp-sdw1
  ... finished key exchange with gp-sdw2
 
[INFO] completed successfully

测试免密连接是否成功:

[root@ gp-master ~]# ssh gp-sdw1 #不需要密码即可登录;

或者:

[root@ gp-master ~]# gpssh -f /home/gpadmin/conf/hostlist
 
=> pwd
[gp-sdw1] /home/gpadmin
[gp-sdw3] /home/gpadmin
[gp-sdw2] /home/gpadmin
[ gp-master] /home/gpadmin
=> exit

出现上面结果就是成功了。
3在Segment节点上安装Greenplum DB

在各个子节点进行文件夹赋权:

chown -R gpadmin:gpadmin /usr/local
chown -R gpadmin:gpadmin /opt

在主节点打包安装包并复制到各个子节点:

[gpadmin@mdw conf]$ cd /usr/local/
打包:
[gpadmin@mdw greenplum]$ tar -cf gp.tar greenplum-db-5.0.0/

[gpadmin@mdw greenplum]$ gpscp -f /home/gpadmin/conf/seg_hosts gp.tar =:/usr/local/

ok,如果没有意外,就批量复制成功了,可以去子节点的相应文件夹查看,之后要将tar包解压,现在我们将采用对子节点使用批量解压操作:

[gpadmin@mdw conf]$ source /usr/local/ greenplum-db/greenplum_path.sh
[gpadmin@mdw conf]$ gpssh -f /home/gpadmin/conf/seg_hosts  #统一处理子节点
 
=> cd /usr/local
[sdw1]
[sdw2]
=> tar -xf gp.tar
[sdw1]
[sdw2]
 
#建立软链接
=> ln -s ./greenplum-db-5.0.0 greenplum-db
[sdw1]
[sdw2]
=> ll(可以使用ll查看一下是否已经安装成功)
=>exit(退出)

这样就完成了所有节点的安装。

初始化数据库
1 创建资源目录

source /usr/local/ greenplum-db/greenplum_path.sh
gpssh -f /home/gpadmin/conf/hostlist #统一处理所有节点
 
#创建资源目录 /opt/greenplum/data下一系列目录(生产目录个数可根据需求生成)
=> mkdir -p /opt/greenplum/data/master
=> mkdir -p /opt/greenplum/data/primary
=> mkdir -p /opt/greenplum/data/mirror
=> mkdir -p /opt/greenplum/data2/primary
=> mkdir -p /opt/greenplum/data2/mirror

2环境变量配置
2.1 在主节点进行环境变量配置

vi /home/gpadmin/.bash_profile 在最后添加
 
source /usr/local/greenplum-db/greenplum_path.sh
export MASTER_DATA_DIRECTORY=/opt/greenplum/data/master/gpseg-1
export GPPORT=5432
export PGDATABASE=gp_sydb

2.2 然后依次复制到各个子节点:

scp /home/gpadmin/.bash_profile gp-sdw1:/home/gpadmin/
。。。

2.3 让环境变量生效:

source .bash_profile

3 NTP 配置

启用master节点上的ntp,并在Segment节点上配置和启用NTP:

echo "server gp-master perfer" >>/etc/ntp.conf
gpssh -f /home/gpadmin/conf/hostlist -v -e 'sudo ntpd'
gpssh -f /home/gpadmin/conf/hostlist -v -e 'sudo /etc/init.d/ntpd start && sudo chkconfig --level 35 ntpd on'

备注:这一步执行比较慢,执行完,时间也没同步成功,不知道为什么。但实际不影响数据库安装。
4 初始化前检查连通性

检查节点与节点之间文件读取;

cd /usr/local/greenplum-db/bin
gpcheckperf -f /home/gpadmin/conf/hostlist -r N -d /tmp
 
--  NETPERF TEST
-------------------
 
====================
==  RESULT
====================
Netperf bisection bandwidth test
gp-master -> gp-sdw1 = 72.220000
gp-sdw2 -> gp-sdw3 = 21.470000
gp-sdw1 -> gp-master = 43.510000
 
Summary:
sum = 181.40 MB/sec
min = 21.47 MB/sec
max = 72.22 MB/sec
avg = 45.35 MB/sec
median = 44.20 MB/sec

出现以上内容证明各个节点已经可以连通。

5 执行初始化

初始化 Greenplum 配置文件模板都在/usr/local/greenplum-db/docs/cli_help/gpconfigs目录下,gpinitsystem_config是初始化 Greenplum 的模板,此模板中 Mirror Segment的配置都被注释;创建一个副本,对其以下配置进行修改:

cd /usr/local/greenplum-db/docs/cli_help/gpconfigs
cp gpinitsystem_config initgp_config
vi initgp_config  
 
#以下为文本要修改的属性字段配置      
#资源目录为在本章节第一步创建的资源目录,配置几次资源目录就是每个子节点有几个实例(推荐4-8个,这里配置了6个,primary与mirror文件夹个数对应)
declare -a DATA_DIRECTORY=(/opt/greenplum/data/primary /opt/greenplum/data/primary /opt/greenplum/data/primary /opt/greenplum/data2/primary /opt/greenplum/data2/primary /opt/greenplum/data2/primary)
declare -a MIRROR_DATA_DIRECTORY=(/opt/greenplum/data/mirror /opt/greenplum/data/mirror /opt/greenplum/data/mirror /opt/greenplum/data2/mirror /opt/greenplum/data2/mirror /opt/greenplum/data2/mirror)

执行初始化;

gpinitsystem -c initgp_config -S

若初始化失败,需要删除/opt下的数据资源目录重新初始化;

若初始化成功,那恭喜你已经安装成功了。

数据库操作
1 停止和启动集群

gpstop -M fast
gpstart -a

2 登录数据库

$ psql -d postgres  #进入某个数据库
 
postgres=# \l # 查询数据库
                 List of databases
   Name    |  Owner  | Encoding |  Access privileges  
-----------+---------+----------+---------------------
 gp_sydb   | gpadmin | UTF8     | 
 postgres  | gpadmin | UTF8     | 
 template0 | gpadmin | UTF8     | =c/gpadmin          
                                : gpadmin=CTc/gpadmin
 template1 | gpadmin | UTF8     | =c/gpadmin          
                                : gpadmin=CTc/gpadmin
(4 rows)
postgres=# \i test.sql #执行sql
postgres=# copy 表名 to '/tmp/1.csv' with 'csv';      #快速导出单表数据
postgres=# copy 表名 from '/tmp/1.csv' with 'csv';    #快速导入单表数据
postgres=# \q          #退出数据库

3 集群状态

gpstate -e #查看mirror的状态
gpstate -f #查看standby master的状态
gpstate -s #查看整个GP群集的状态
gpstate -i #查看GP的版本
gpstate --help #帮助文档,可以查看gpstate更多用法

目前为止数据库已经操作完毕。默认只有本地可以连数据库,如果需要别的可以连,需要修改gp_hba.conf文件,具体这里不再赘述。

安装文件下载地址
https://network.pivotal.io/products/pivotal-gpdb/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值