CentOS7安装配置GreenPlum6

1.服务器配置

主机名 主机IP 规格 数据盘-1 数据盘-2 说明
gp-master01 172.26.2.171 4 vCPU 8 GiB 40GB系统盘 ESSD 100GB segment节点,创建2个segment( 每个节点的磁盘独立)
gp-segment01 172.26.2.172 4 vCPU 8 GiB 40GB系统盘 ESSD 200GB ESSD 200GB segment节点,创建2个segment( 每个节点的磁盘独立)
gp-segment02 172.26.2.173 4 vCPU 8 GiB 40GB系统盘 ESSD 200GB ESSD 200GB master节点,暂不考虑standby节点

2.系统配置

2.1 配置主机名(所有节点)

注:这里的主机名为后续gp数据库之间通信的关键,为方便管理需统一主机名命名规范,如上表所示。

# 在主机172.26.2.171执行
[root@localhost ~]# hostnamectl set-hostname gp-master01
[root@localhost ~]# echo '172.26.2.171    gp-master01     gp-master01' >> /etc/hosts
# 在主机172.26.2.172执行
[root@localhost ~]# hostnamectl set-hostname gp-segment01
[root@localhost ~]#echo '172.26.2.172    gp-segment01     gp-segment01' >> /etc/hosts
# 在主机172.26.2.173执行
[root@localhost ~]# hostnamectl set-hostname gp-segment02
[root@localhost ~]# echo '172.26.2.173    gp-segment02     gp-segment02' >> /etc/hosts
  • 配置/etc/hosts (所有机器)
添加每台机器的ip 和hostname,确保所有机器的/etc/hosts中包含以下信息
172.26.2.171    gp-master01
172.26.2.172    gp-segment01
172.26.2.173    gp-segment02

2.2 为所有主机创建gp用户(所有节点)

[root@localhost ~]# groupadd gpadmin 
[root@localhost ~]# useradd gpadmin -r -m -g gpadmin 
# 密码可根据实际情况考虑是否设置,我这里用root切换,所以就不设置密码了。
# echo "qwert" | passwd --stdin gpadmin

2.3 修改系统内核/etc/sysctl.conf文件(所有节点)

  • 编辑文件vim /etc/sysctl.conf

    vm.swappiness = 0
    vm.overcommit_memory = 1 #说明在最后
    kernel.core_uses_pid = 1
    kernel.sysrq = 1
    kernel.shmall = 197951838 #控制可以使用的共享内存的总页数
    kernel.shmmax = 810810728448 #定义单个共享内存段的最大值,建议值为多于物理内存的一半,可取的最大值为物理内存值 -1byte  
    kernel.shmmni = 4096 #默认值4096 
    kernel.sem = 500 2048000 200 4096
    kernel.msgmnb = 65536
    kernel.msgmax = 65536
    kernel.msgmni = 2048
    
    net.ipv4.neigh.default.gc_stale_time = 120
    
    net.ipv4.conf.all.rp_filter = 0
    net.ipv4.conf.default.rp_filter = 0
    net.ipv4.conf.default.arp_announce = 2
    net.ipv4.conf.lo.arp_announce = 2
    net.ipv4.conf.all.arp_announce = 2
    
    # see details in https://help.aliyun.com/knowledge_detail/41334.html
    net.ipv4.tcp_max_tw_buckets = 5000
    net.ipv4.tcp_syncookies = 1
    net.ipv4.tcp_max_syn_backlog = 4096 #所能接受SYN同步包的最大客户端数量
    net.ipv4.conf.all.arp_filter = 1
    net.core.netdev_max_backlog = 10000
    net.ipv4.tcp_tw_recycle = 1 #表示开启TCP连接中TIME-WAIT sockets的快速回收,默认为0,表示关闭
    net.ipv4.ip_local_port_range = 1025 65535
    net.ipv4.tcp_synack_retries = 2
    net.ipv4.tcp_slow_start_after_idle = 0

    说明:

    vm.overcommit_memory可选值:0,1,2。

    0,:表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否 则,内存申请失败,并把错误返回给应用进程。

    1:(推荐)表示内核允许分配所有的物理内存,而不管当前的内存状态如何。

    2: 表示内核允许分配超过所有物理内存和交换空间总和的内存

    kernel.shmall参考值:

    当内存为 12G 时, kernel.shmall = 3145728

    当内存为 16G 时, kernel.shmall = 4194304

    当内次为 32G 时, kernel.shmall = 8388608

    当内存为 64G 时, kernel.shmall = 16777216

    当内存为 128G 时, kernel.shmall = 33554432

    kernel.sem 参数说明:

    500 信号集容纳最大信号数量

    2048000 所有信号的最大数量

    200 调用单个信号集中最大信号数量

    40960 信号集的最大值

    kernel.msgmni:表示系统内最大消息队列个数 kernel.msgmnb:表示单个消息队列的最大容量 kernel.msgmax:表示消息队列中单个消息的最大容量

    net.core.netdev_max_backlog 表示当每个网络接口 接受数据包的速率比内核处理这些包的速率快时,允许发送到队列的数据包的最大数目

2.4 修改系统资源限制(所有节点)

  • 编辑文件vim /etc/security/limits.conf
* soft nofile 524288
* hard nofile 524288
* soft nproc 131072 
* hard nproc 131072
  • 修改SSH连接阈值vim /etc/ssh/sshd_config

    MaxStartups 300:30:1000
    # 重启sshd,使参数生效
    [root@localhost ~]# systemctl restart sshd

2.5 关闭selinux和防火墙(所有节点)

# 1.查看selinux状态
[root@localhost ~]# getenforce
Disabled
[root@localhost ~]# /usr/sbin/sestatus -v
SELinux status:                 disabled
# 2.临时关闭selinux
##设置SELinux 成为permissive模式
##setenforce 1 设置SELinux 成为enforcing模式
[root@localhost ~]# setenforce 0
# 3.永久关闭selinux
[root@localhost ~]# vim /etc/selinux/config
#将SELINUX=enforcing改为SELINUX=disabled 
#设置后需要重启才能生效
# 4.关闭防火墙
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# systemctl stop firewalld

2.6 磁盘分区挂载

2.6.1 安装lvm软件(所有节点)

[root@localhost ~]# yum install -y lvm2

2.6.2 gp-master01节点磁盘分区挂载

  1. 查看磁盘列表

    [root@localhost ~]# fdisk -l
    
    Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x000b770c
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048    83886046    41941999+  83  Linux
    
    Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
  2. 创建PV

    [root@localhost ~]# pvcreate /dev/vdb
      Physical volume "/dev/vdb" successfully created.
    1. 创建VG
    [root@localhost ~]# vgcreate gp /dev/vdb
      Volume group "gp" successfully created
  3. 创建LV

    [root@localhost ~]# lvcreate -l 100%VG gp -n master
      Logical volume "master" created.
  4. 挂载LV到目录

    # 创建目录
    [root@localhost ~]# mkdir -p /data/master
    # 格式化分区
    [root@localhost ~]# mkfs.xfs /dev/gp/master 
    # 挂载目录
    [root@localhost ~]# mount /dev/gp/master /data/master
  5. 开机自动挂载

    • 编辑文件vim /etc/fstab
    # 文件最后追加以下内容
    /dev/gp/master /data/master xfs defaults 0 0

2.6.3 gp-segment01节点磁盘分区挂载

  1. 查看磁盘列表

    [root@localhost ~]# fdisk -l
    
    Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x000b770c
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048    83886046    41941999+  83  Linux
    
    Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    
    
    Disk /dev/vdc: 214.7 GB, 214748364800 bytes, 419430400 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    
    
    Disk /dev/vdd: 429.5 GB, 429496729600 bytes, 838860800 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
  2. 创建PV

    [root@localhost ~]# pvcreate /dev/vdb
      Physical volume "/dev/vdb" successfully created.
    [root@localhost ~]# pvcreate /dev/vdc
      Physical volume "/dev/vdb" successfully created.
    [root@localhost ~]# pvcreate /dev/vdd
      Physical volume "/dev/vdd" successfully created.
  3. 创建VG

    [root@localhost ~]# vgcreate gp-segment01 /dev/vdb
      Volume group "gp-segment01" successfully created
    [root@localhost ~]# vgcreate gp-segment02 /dev/vdc
      Volume group "gp-segment02" successfully created
    [root@localhost ~]# vgcreate gp-mirror /dev/vdd
      Volume group "gp-mirror" successfully created
  4. 创建LV

    [root@localhost ~]# lvcreate -l 100%VG gp-segment01 -n data
      Logical volume "data" created.
    [root@localhost ~]# lvcreate -l 100%VG gp-segment02 -n data
      Logical volume "data" created.
    [root@localhost ~]# lvcreate -l 100%Vg gp-mirror -n data
      Logical volume "data" created.
  5. 挂载LV到目录

    # 创建目录
    [root@localhost ~]# mkdir -p /data/segment01
    [root@localhost ~]# mkdir -p /data/segment02
    [root@localhost ~]# mkdir -p /data/mirror
    # 格式化分区
    [root@localhost ~]# mkfs.xfs /dev/gp-segment01/data
    [root@localhost ~]# mkfs.xfs /dev/gp-segment02/data
    [root@localhost ~]#mkfs.xfs /dev/gp-mirror/data
    # 挂载目录
    [root@localhost ~]# mount /dev/gp-segment01/data /data/segment01
    [root@localhost ~]# mount /dev/gp-segment02/data /data/segment02
    [root@localhost ~]# mount /dev/gp-mirror/data /data/mirror
  6. 开机自动挂载

    • 编辑文件vim /etc/fstab
    # 文件最后追加以下内容
    /dev/gp-segment01/data /data/segment01 xfs defaults 0 0
    /dev/gp-segment02/data /data/segment02 xfs defaults 0 0
    /dev/gp-mirror/data /data/mirror xfs defaults 0 0

2.6.4 gp-segment02节点磁盘分区挂载

  1. 查看磁盘列表

    [root@localhost ~]# fdisk -l
    
    Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x000b770c
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048    83886046    41941999+  83  Linux
    
    Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    
    
    Disk /dev/vdc: 214.7 GB, 214748364800 bytes, 419430400 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    
    
    Disk /dev/vdd: 429.5 GB, 429496729600 bytes, 838860800 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
  2. 创建PV

    [root@localhost ~]# pvcreate /dev/vdb
      Physical volume "/dev/vdb" successfully created.
    [root@localhost ~]# pvcreate /dev/vdc
      Physical volume "/dev/vdb" successfully created.
    [root@localhost ~]# pvcreate /dev/vdd
      Physical volume "/dev/vdd" successfully created.
  3. 创建VG

    [root@localhost ~]# vgcreate gp-segment01 /dev/vdb
      Volume group "gp-segment01" successfully created
    [root@localhost ~]# vgcreate gp-segment02 /dev/vdc
      Volume group "gp-segment02" successfully created
    [root@localhost ~]# vgcreate gp-mirror /dev/vdd
      Volume group "gp-mirror" successfully created
  4. 创建LV

    [root@localhost ~]# lvcreate -l 100%VG gp-segment01 -n data
      Logical volume "data" created.
    [root@localhost ~]# lvcreate -l 100%VG gp-segment02 -n data
      Logical volume "data" created.
    [root@localhost ~]# lvcreate -l 100%Vg gp-mirror -n data
      Logical volume "data" created.
  5. 挂载LV到目录

    # 创建目录
    [root@localhost ~]# mkdir -p /data/segment01
    [root@localhost ~]# mkdir -p /data/segment02
    [root@localhost ~]# mkdir -p /data/mirror
    # 格式化分区
    [root@localhost ~]# mkfs.xfs /dev/gp-segment01/data
    [root@localhost ~]# mkfs.xfs /dev/gp-segment02/data
    [root@localhost ~]#mkfs.xfs /dev/gp-mirror/data
    # 挂载目录
    [root@localhost ~]# mount /dev/gp-segment01/data /data/segment01
    [root@localhost ~]# mount /dev/gp-segment02/data /data/segment02
    [root@localhost ~]# mount /dev/gp-mirror/data /data/mirror
  6. 开机自动挂载

    • 编辑文件vim /etc/fstab
    # 文件最后追加以下内容
    /dev/gp-segment01/data /data/segment01 xfs defaults 0 0
    /dev/gp-segment02/data /data/segment02 xfs defaults 0 0
    /dev/gp-mirror/data /data/mirror xfs defaults 0 0

3.Greenplum安装

3.1 安装依赖(所有节点)

[root@gp-master01 ~]# yum install -y zip unzip openssh-clients ed ntp net-tools perl perl-devel perl-ExtUtils* mlocate lrzsz parted apr apr-util bzip2 krb5-devel libevent libyaml rsync lrzsz

3.2 安装greenplum(每个节点都需要安装)

3.2.1 下载安装包

[root@gp-master01 ~]# wget https://github.com/greenplum-db/gpdb/releases/download/6.22.2/open-source-greenplum-db-6.22.2-rhel7-x86_64.rpm

3.2.2 安装数据库

# 创建安装目录
[root@gp-master01 ~]# mkdir -p /data/gp
# 安装数据库
# 说明:--prefix=/data/gp 为指定的安装路径,可自己修改
[root@gp-master01 ~]# rpm -ivh --prefix=/data/gp open-source-greenplum-db-6.22.2-rhel7-x86_64.rpm

3.2.3 配置greenplum环境变量(用户:gpadmin)

# 授权目录
[root@gp-master01 ~]# chown -R gpadmin:gpadmin /data
# 切换gpadmin用户
[root@gp-master01 ~]# su gpadmin -s /bin/bash
[root@gp-master01 ~]# echo 'source /data/gp/greenplum-db/greenplum_path.sh' >> ~/.bashrc
[root@gp-master01 ~]# source  ~/.bashrc

3.2.4 配置免密登录(用户:gpadmin)

  • 生成密钥
# 只需在master节点操作
# -C 'gp-master01'为主机名,方便识别
# 提示语不用管,一直按Enter键使用默认值即可
[gpadmin@gp-master01 ~]$ ssh-keygen -C 'gp-master01'
  • 将本机的公钥复制到各个节点机器的authorized_keys文件中
[gpadmin@gp-master01 ~]$ ssh-copy-id gpadmin@gp-master01
[gpadmin@gp-master01 ~]$ ssh-copy-id gpadmin@gp-segment01
[gpadmin@gp-master01 ~]$ ssh-copy-id gpadmin@gp-segment02
  • 安装pip和python依赖
# 下载pip安装脚本
[gpadmin@gp-master01 ~]$ wget -c 'https://bootstrap.pypa.io/pip/2.7/get-pip.py' -O get-pip.py
# 安装pip
[gpadmin@gp-master01 ~]$ python get-pip.py
# 暗黄依赖
[gpadmin@gp-master01 ~]$ pip install psutil lockfile paramiko setuptools epydoc pyyaml
  • 修改pip源为阿里云源
[gpadmin@gp-master01 ~]$ mkdir ~/.pip   #创建文件夹
[gpadmin@gp-master01 ~]$ cd ~/.pip        #进入目录
[gpadmin@gp-master01 ~]$ vim pip.conf        #编辑配置文件(内容如下)

# 替换阿里镜像源(或其他镜像源)
[global]
trusted-host = mirrors.aliyun.com
index-url = https://mirrors.aliyun.com/pypi/simple 
  • 使用gpssh-exkeys 工具,打通n-n的免密登陆

[gpadmin@gp-master01 ~]$ vim all_host
# 增加所有hostname到文件中
gp-master01
gp-segment01
gp-segment02
[gpadmin@gp-master01 ~]$ gpssh-exkeys -f all_host

3.2.5 校验你硬件以及网络性能

Greenplum提供了一个管理工具叫做gpcheckperf,它可以被用来测试以下性能:

  • 校验网络性能
[gpadmin@gp-master01 ~]$ gpcheckperf -f segment_host -r N -d /tmp > ~/check_out/subnet1.out
  • 校验磁盘I/O性能和内存带宽
[gpadmin@gp-master01 ~]$ gpcheckperf -f segment_host -r ds -D -d /data/segment01 > ~/check_out/iocheck.out

这个工具可能会花费好一会来进行测试,因为它将在节点间复制大量的文件,当它结束时,你将会看见磁盘读写的总结果

[gpadmin@gp-master01 ~]$ cat ~/check_out/iocheck.out
====================
==  RESULT 2022-11-23T11:18:13.875745
====================

 disk write avg time (sec): 44.40
 disk write tot bytes: 31673548800
 disk write tot bandwidth (MB/s): 978.50
 disk write min bandwidth (MB/s): 219.17 [gp-segment01]
 disk write max bandwidth (MB/s): 759.33 [gp-segment02]
 -- per host bandwidth --
    disk write bandwidth (MB/s): 219.17 [gp-segment01]
    disk write bandwidth (MB/s): 759.33 [gp-segment02]


 disk read avg time (sec): 44.16
 disk read tot bytes: 31673548800
 disk read tot bandwidth (MB/s): 988.54
 disk read min bandwidth (MB/s): 219.94 [gp-segment01]
 disk read max bandwidth (MB/s): 768.61 [gp-segment02]
 -- per host bandwidth --
    disk read bandwidth (MB/s): 219.94 [gp-segment01]
    disk read bandwidth (MB/s): 768.61 [gp-segment02]


 stream tot bandwidth (MB/s): 39220.90
 stream min bandwidth (MB/s): 19102.50 [gp-segment01]
 stream max bandwidth (MB/s): 20118.40 [gp-segment02]
 -- per host bandwidth --
    stream bandwidth (MB/s): 19102.50 [gp-segment01]
    stream bandwidth (MB/s): 20118.40 [gp-segment02]

3.3 集群初始化(用户:gpadmin)

3.3.1 编写初始化配置文件

# 拷贝配置文件模板
[gpadmin@gp-master01 ~]$ mkdir ~/gpconfigs
[gpadmin@gp-master01 ~]$ cp $GPHOME/docs/cli_help/gpconfigs/gpinitsystem_config ~/gpconfigs/gpinitsystem_config

3.3.2 根据需要修改参数

[gpadmin@gp-master01 ~]$  vim /home/gpadmin/gpconfigs/gpinitsystem_config

注意:To specify PORT_BASE, review the port range specified in the net.ipv4.ip_local_port_range parameter in the /etc/sysctl.conf file.

主要修改的参数:

#primary的数据目录
declare -a DATA_DIRECTORY=(/data/segment01 /data/segment02)
#master节点的hostname
MASTER_HOSTNAME=gp-master01
#master节点的主目录
MASTER_DIRECTORY=/data/master
#mirror的端口要把前面的#去掉(启用mirror)
MIRROR_PORT_BASE=7000
#mirror的数据目录要把前面的#去掉(启用mirror)
declare -a MIRROR_DATA_DIRECTORY=(/data/mirror /data/mirror)

3.3.3 集群初始化

  • 执行脚本
gpinitsystem -c /home/gpadmin/gpconfigs/gpinitsystem_config --locale=C -h /home/gpadmin/segment_host
  • 失败回退
# 安装中途失败,提示使用  bash /home/gpadmin/gpAdminLogs/backout_gpinitsystem_gpadmin_* 回退,执行该脚本即可,例如:
0221123:12:01:02:004038 gpinitsystem:gp-master01:gpadmin-[INFO]:-Checking new segment hosts, please wait...
...../bin/touch: cannot touch ‘/data/mirror/tmp_file_test’: Permission denied
20221123:12:01:05:004038 gpinitsystem:gp-master01:gpadmin-[FATAL]:-Cannot write to /data/mirror on gp-segment02  Script Exiting!
20221123:12:01:05:004038 gpinitsystem:gp-master01:gpadmin-[WARN]:-Script has left Greenplum Database in an incomplete state
20221123:12:01:05:004038 gpinitsystem:gp-master01:gpadmin-[WARN]:-Run command bash /home/gpadmin/gpAdminLogs/backout_gpinitsystem_gpadmin_20221123_120059 on master to remove these changes
  • 执行回退
[gpadmin@gp-master01 ~]$ bash /home/gpadmin/gpAdminLogs/backout_gpinitsystem_gpadmin_20221123_120059

3.3.4 安装成功后配置

# psql 登陆gp 并设置密码(gpadmin用户)
psql -h hostname -p port -d database -U user -W password
# -h后面接对应的master或者segment主机名
# -p后面接master或者segment的端口号
# -d后面接数据库名可将上述参数配置到用户环境变量中,linux 中使用gpadmin用户不需要密码。

[gpadmin@gp-master01 ~]$ psql -h 127.0.0.1 -p 5432 -d postgres -U gpadmin 

# psql 登录,并设置gpadmin用户密码示例:
[gpadmin@gp-master01 ~]$  psql -d postgres
[gpadmin@gp-master01 ~]$  alter user gpadmin encrypted password 'gpadmin';

3.3.5 客户端登录GP

客户端认证是由一个配置文件(通常名为pg_hba.conf)控制的, 它存放在数据库集群的数据目录里。HBA的意思是host-based authentication, 也就是基于主机的认证。在initdb初始化数据目录的时候, 它会安装一个缺省的pg_hba.conf文件。不过我们也可以把认证配置文件放在其它地方

  • 配置 pg_hba.conf
[gpadmin@gp-master01 ~]$  vim /data/master/gpseg-1/pg_hba.conf
 # 文件最后新增一行 
 host all all 0.0.0.0/0 trust
 # 加载修改的文件
 [gpadmin@gp-master01 ~]$  gpstop -u 

3.3.6 客户端尝试登录


CentOS7安装配置GreenPlum6
https://www.gmtgo.com/241.html
作者
大帅
发布于
2022年11月23日
许可协议