• Greenplum学习笔记——第二部分:集群部署


    Greenplum 安装

    前期准备

    1、Greenplum集群规划

    192.168.5.107 Master sdw1

    192.168.5.108 sdw2

    192.168.5.109 sdw3

    192.168.5.107即作为Master节点也作为Segment节点,正式环境不推荐此做法,正式环境下Master应该单独一台服务器;192.168.5.108、192.168.5.109作为Segment节点,每个机器上配置两个Primary Segment和两个Mirror Segment。

    2、操作系统准备

    Greenplum没有Windows版本,只能安装在类UNIX的操作系统上,我们选择Centos7进行安装。

    3、数据库存储

    对于Greenplum数据库来说,在性能上磁盘IO很容易成为瓶颈,由于数据库的特性,每一个SQL基本都是对全部数据进行分析,每次处理的数据量非常大,数据基本上都是没有缓存的(数据字典除外),极度消耗IO资源(全表扫描主要都是顺序IO),所以Greenplum对于存储的要求比较高。在文件系统上,Linux下建议使用XFS,在Solaris下建议使用ZFS,对于性能有更高的要求,可以选择Raid 1+0。

    4、网络

    在确定机器配置时,要保证所有机器的网络都是通的,并且每台机器的防火墙都是关闭的,避免存在网络不通的问题。

    在配置/etc/hosts时,习惯将Master机器叫做mdw,将Segment机器叫做sdw,配置好后,使用ping命令确定所有hostname都是通的。

    在所有机器配置:

    # dw-greenplum-* 是机器主机名
    192.168.5.107 dw-greenplum-1 mdw sdw1
    192.168.5.108 dw-greenplum-2 sdw2
    192.168.5.109 dw-greenplum-3 sdw3
    
    • 1
    • 2
    • 3
    • 4

    5、时间

    方法一:启用master节点上的NTP,并在Segment节点上配置和启用NTP。

    方法二:同步其他机器的时间,需要确保目标机器已经开启了NTP服务。

    1、安装ntpdate

    yum install ntpdate -y
    
    • 1

    2、同步时间

    # 同步目标主机时间,需要确保目标机器已经开启了NTP服务
    ntpdate -u 目标主机
    
    • 1
    • 2

    系统配置

    1、配置Selinux

    临时关闭:输入命令setenforce 0,重启系统后还会开启。

    永久关闭:输入命令vi /etc/selinux/config,将SELINUX=enforcing改为SELINUX=permissive,然后保存退出。

    2、服务器参数调整

    ~ cat /etc/sysctl.conf
    
    kernel.shmmax = 500000000
    kernel.shmmni = 4096
    kernel.shmall = 4000000000
    kernel.sem = 50100 128256000 50100 2560
    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.conf.default.accept_source_route = 0
    net.ipv4.tcp_tw_recycle = 1
    net.ipv4.tcp_max_syn_backlog = 4096
    net.ipv4.conf.defalut.arp_filter = 1
    net.ipv4.conf.all.arp_filter = 1
    net.ipv4.ip_local_port_range = 10000 65535
    net.core.netdev_max_backlog = 10000
    net.core.rmem_max = 2097152
    net.core.wmem_max = 2097152
    vm.overcommit_memory = 2
    kernel.core_pattern = /var/core/core.%h.%t
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    3、系统资源限制调整

    ~ cat /etc/security/limits.conf
    
    * soft  nofile 65536
    * hard  nofile 65536
    * soft  nproc 131072
    * hard  nproc 131072
    * soft  core unlimited
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    4、创建用户及用户组

    创建gpadmin用户及用户组,将其作为安装Greenplum的操作系统用户

    创建新的用户和用户组:

    groupadd -g 530 gpadmin
    useradd -g 530 -u 530 -m -d /home/gpadmin -s /bin/bash gpadmin
    
    • 1
    • 2

    对文件夹进行赋权,为新用户创建密码:

    chown -R gpadmin:gpadmin /home/gpadmin
    passwd gpadmin
    
    • 1
    • 2

    Greenplum安装

    1、安装数据库软件

    下载地址:https://network.pivotal.io/products/vmware-tanzu-greenplum 选择所需要的下载版本与对应的操作系统,下载时需要注册一个Greenplum用户,请耐心注册。

    当下载好安装包后你已经成功一半了。

    以6.16.1为例:

    安装包名称:greenplum-db-6.16.1-rhel7-x86_64.rpm

    安装步骤:

    (1)执行yum 安装 或 rpm安装,大家安装时不要紧张,Greenplum软件按照相对简单,按步骤执行就好。

    yum install greenplum-db-6.16.1-rhel7-x86_64.rpm -y
    或
    rpm -ivh greenplum-db-6.16.1-rhel7-x86_64.rpm
    
    • 1
    • 2
    • 3

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

    chown -R gpadmin:gpadmin /usr/local
    
    • 1

    这时切换到gpadmin,刷新Greenplum环境变量查看Greenplum是否安装完成

    $ su - gpadmin
    $ source /usr/local/greenplum-db/greenplum_path.sh
    $ gpstate --version
    # 显示以下信息说明Greenplum软件安装成功
    gpstate version 6.16.1 build commit:10171814c15886ff864fad19b89b3a7c224e0a97
    
    • 1
    • 2
    • 3
    • 4
    • 5

    (2)配置集群hostlist文件,打通节点

    a. 创建hostlist文件与seg_hosts文件,hostlist文件包含所有主机信息,seg_hosts包含Segment主机信息。

    hostlist

    [gpadmin@dw-greenplum-1 ~]$ more hostlist 
    mdw
    sdw1
    sdw2
    sdw3
    
    • 1
    • 2
    • 3
    • 4
    • 5

    seg_hosts

    [gpadmin@dw-greenplum-1 ~]$ more seg_hosts 
    sdw1
    sdw2
    sdw3
    
    • 1
    • 2
    • 3
    • 4

    b. 配置ssh免密连接。

    $ su - gpadmin
    $ source /usr/local/greenplum-db/greenplum_path.sh
    $ gpssh-exkeys -f hostlist
    # 然后按要求执行即可
    
    • 1
    • 2
    • 3
    • 4

    测试免密连接是否成功:

    # root账号 和 gpadmin账号免密远程Segment节点是否成功
    $ ssh sdw2
    # gpssh 工具批量控制其他服务器是否成功
    $ gpssh -f hostlist
    => pwd
    [sdw3] /home/gpadmin
    [ mdw] /home/gpadmin
    [sdw2] /home/gpadmin
    => 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    如果使用gpssh-exkeys打通各节点失败,大家可以使用Linux自带的免密登录打通

    # 需要在root用户和gpadmin用户都执行,确保集群间能过通过这两个用户免密登录
    # 生成密钥
    ssh-keygen -t rsa
    # 拷贝密钥到其他主机
    ssh-copy-id sdw2
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2、在Segment节点上安装Greenplum

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

    # 创建合适的目录,并为其授权
    mkdir /xswork
    chown gpadmin:gpadmin work
    
    • 1
    • 2
    • 3

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

    tar -cf /home/gpadmin/gp6.16.tar.gz greenplum-db-6.16.1/
    cd /usr/local
    chown gpadmin:gpadmin gp6.16.tar.gz
    su - gpadmin
    gpscp -f hostlist gp6.16.tar.gz =:/xswork/
    
    • 1
    • 2
    • 3
    • 4
    • 5

    这个时候如果没有意外,greenplum的文件已经复制到各个Segment机器的/xswork目录下了,可以去各个字节点检查一下

    su - gpadmin
    gpssh -f seg_hosts
    => cd /xswork
    [sdw2]
    [sdw3]
    [sdw1]
    => ll
    [sdw2] total 535780
    [sdw2] -rw-------.  1 gpadmin gpadmin 548638720 Jul  6 15:22 gp6.16.tar.gz
    [sdw3] total 535780
    [sdw3] -rw-------.  1 gpadmin gpadmin 548638720 Jul  6 15:22 gp6.16.tar.gz
    [sdw1] total 535780
    [sdw1] -rw-------.  1 gpadmin gpadmin 548638720 Jul  6 15:21 gp6.16.tar.gz
    => 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    没有问题的话批量解压:

    su - gpadmin
    gpssh -f seg_hosts
    => cd /xswork
    [sdw3]
    [sdw1]
    [sdw2]
    => tar -xf gp6.16.tar.gz
    [sdw3]
    [sdw1]
    [sdw2]
    #建立软链接
    => ln -s greenplum-db-6.16.1 greenplum-db
    [sdw3]
    [sdw1]
    [sdw2]
    =>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    3、初始化集群

    (1)创建资源目录

    # 主节点上执行
    su - gpadmin
    # 创建主节点目录
    mkdir -p /xswork/data/master/gpseg-1
    # 创建各个Segment节点目录
    gpssh -f seg_hosts
    # 因为我们每个集群计划部署两个Segment节点与镜像,因此创建两个目录即可,也可只创建/xswork/primary 和 /xswork/mirror目录,初始化时会按目录有区分,这个根据个人喜好创建
    => mkdir -p /xswork/primary/gpdatap1
    => mkdir -p /xswork/primary/gpdatap2
    => mkdir -p /xswork/mirror/gpdatam1
    => mkdir -p /xswork/mirror/gpdatam2
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    (2)配置环境变量

    su - gpadmin
    # 主节点配置环境变量
    vi ~/.bash_profile
    # .bash_profile
    
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
    	. ~/.bashrc
    fi
    
    # User specific environment and startup programs
    source /xswork/greenplum-db/greenplum_path.sh
    export MASTER_DATA_DIRECTORY=/xswork/data/master/gpseg-1/gpseg-1
    export PGPORT=12354
    export PGDATABASE=testDB
    PATH=$PATH:$HOME/.local/bin:$HOME/bin
    
    export PATH
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    主节点配置好后复制到Segment节点

    (3)初始化前测试集群机器的性能

    网络测试:

    gpcheckperf -d 目录 upload -r N -f 主机列表文件
    
    • 1

    文件系统性能验证:

    gpcheckperf -d 目录1 -d 目录2 upload -r ds -D -f 主机列表文件
    
    • 1

    (4)执行初始化

    初始化 Greenplum 配置文件模板都在/usr/local/greenplum-db/docs/cli_help/gpconfigs目录下,gpinitsystem_config是初始化 Greenplum 的模板。

    gpinitsystem_config

    # FILE NAME: gpinitsystem_config
    
    # Configuration file needed by the gpinitsystem
    
    ################################################
    #### REQUIRED PARAMETERS
    ################################################
    
    #### Name of this Greenplum system enclosed in quotes.
    ARRAY_NAME="Greenplum Data Platform"
    
    #### Naming convention for utility-generated data directories.
    SEG_PREFIX=gpseg
    
    #### Base number by which primary segment port numbers 
    #### are calculated.
    PORT_BASE=6000
    
    #### File system location(s) where primary segment data directories 
    #### will be created. The number of locations in the list dictate
    #### the number of primary segments that will get created per
    #### physical host (if multiple addresses for a host are listed in 
    #### the hostfile, the number of segments will be spread evenly across
    #### the specified interface addresses).
    declare -a DATA_DIRECTORY=(/xswork/primary/gpdatap1 /xswork/primary/gpdatap2)
    
    #### OS-configured hostname or IP address of the master host.
    MASTER_HOSTNAME=mdw
    
    #### File system location where the master data directory 
    #### will be created.
    MASTER_DIRECTORY=/xswork/data/master/gpseg-1
    
    #### Port number for the master instance. 
    MASTER_PORT=5432
    
    #### Shell utility used to connect to remote hosts.
    TRUSTED_SHELL=ssh
    
    #### Maximum log file segments between automatic WAL checkpoints.
    CHECK_POINT_SEGMENTS=8
    
    #### Default server-side character set encoding.
    ENCODING=UNICODE
    
    ################################################
    #### OPTIONAL MIRROR PARAMETERS
    ################################################
    
    #### Base number by which mirror segment port numbers 
    #### are calculated.
    MIRROR_PORT_BASE=7000
    
    REPLICATION_PORT_BASE=8000
    MIRROR_REPLICATION_PORT_BASE=9000
    #### File system location(s) where mirror segment data directories 
    #### will be created. The number of mirror locations must equal the
    #### number of primary locations as specified in the 
    #### DATA_DIRECTORY parameter.
    declare -a MIRROR_DATA_DIRECTORY=(/xswork/mirror/gpdatam1 /xswork/mirror/gpdatam2)
    
    
    ################################################
    #### OTHER OPTIONAL PARAMETERS
    ################################################
    
    #### Create a database of this name after initialization.
    #DATABASE_NAME=name_of_database
    
    #### Specify the location of the host address file here instead of
    #### with the -h option of gpinitsystem.
    MACHINE_LIST_FILE=/home/gpadmin/seg_hosts
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72

    执行初始化

    gpinitsystem -c gpconfigs/gpinitsystem_config
    
    • 1

    然后按要求执行整个集群就初始化完成了。

    总结

    安装Greenplum主要有以下步骤:

    1、集群的规划与服务器准备;

    2、服务器的配置;

    3、在Master安装Greenplum软件,这一步在Master节点操作就好;

    4、复制Master安装好的Greenplum软件到Segment节点中;

    5、配置gpinitsystem_config配置文件,需要注意的是MASTER_DIRECTORY、DATA_DIRECTORY、MIRROR_DATA_DIRECTORY参数;

    6、执行初始化 gpinitsystem -c gpconfigs/gpinitsystem_config,初始化时如果不指定主机,则默认使用gpinitsystem_config配置中MACHINE_LIST_FILE指定的主机列表;

  • 相关阅读:
    用纹理图集优化3D场景性能【Texture Atlas】
    MySQL集群高可用架构之MHA
    el-table 实现表、表格行、表格列合并
    C语言课程设计题目汇总与要求
    这次把怎么做好一个PPT讲清-动画篇
    Java项目:JSP健身房管理系统
    Monaco Editor 中的 Keybinding 机制
    【Vue】动态组件和异步组件
    Spark RDD弹性分布式数据集
    心脑体漫画版本
  • 原文地址:https://blog.csdn.net/xingshiyunwei/article/details/126128180