Greenplum 源码安装教程 —— 以 CentOS 平台为例

Greenplum 源码安装教程

作者:Arthur_Qin 禾众

Greenplum 主体以及orca ( 新一代优化器 ) 的代码以可以从 Github 上下载。如果不打算查看代码,想下载编译好的二进制版可以访问其母公司 pivotal 官网 下载,具体配置安装流程可以参考《Greenplum 安装》

正文由此开始:

1 Greenplum 介绍

Greenplum is built on PostgreSQL and operates as a data warehouse and uses a shared-nothing, massively parallel processing (MPP) architecture, available under the terms of the GNU General Public License, owned by Pivotal. ——Greenplum Wikipedia article 

本文主要记录 Greenplum 的源码安装过程,对 Greenplum 架构和历史感兴趣的推荐阅读 《聊聊Greenplum的那些事》 ,以及我的另一篇博文 《Greenplum 的分布式框架结构》

2 安装环境及软件版本

参数 版本
主机数量 3台虚拟机,单核1.5G内存 (1台作为 master, 2台作为 slave),能联网
主机系统 Centos6.7
Greenplum 版本 201609 Github 版 (4.3.X)

如果使用远程服务器安装,且远程服务器不能直接联网的,可通过同网段下其他主机代理联网。详情可搜索关键字 ccproxy 代理

这里使用1个master,2个slave,ip为

​ 10.77.100.121

​ 10.77.100.122

​ 10.77.100.123

其中10.77.100.121为master,其余为segment。

可以使用的内网 ip ,也可以使用外网 ip ,能相互 ping 通就可以。

(虚拟机上网的话其实是可以与主机共享网络的,可以把网络连接的网络共享给vmware虚拟机网络,请参考 《VMware虚拟机NAT模式的具体配置》 或者 《虚拟机无法共享主机网络无法上网怎么办?》,然后在 Greenplum 的配置文件中使用 192开头的 ip 即可)

3 安装准备工作

3.1 修改hosts(所有机器)

这里主要是为之后Greenplum能够在各个节点之间相互通信做准备

[root@dw-greenplum-1 conf]#  vi /etc/hosts

127.0.0.1 localhost localhost.localdomain

10.77.100.121 dw-greenplum-1 mdw

10.77.100.122 dw-greenplum-2 sdw1

10.77.100.123 dw-greenplum-3 sdw2

这一定要用自己的 ip 啊,不要直接复制粘贴上面的。

配置了这个文件之后,一定要同时修改 /etc/sysconfig/network这个文件如下(所有机器都要修改):

[root@dw-greenplum-1 conf]#  vi /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=dw-greenplum-1 #其他的机子将 -1 改为 -2 -3 ...

这里的HOSTNAME一定要与/etc/hosts中的主机名一致,最终可以使用ping + 主机名 测试是否配置好。

  • :修改了/etc/sysconfig/network文件之后,可以将/home/gpadmin/.gphostcache删除掉,因为如果在修改network文件之前执行过gpssh-exkeys,可能会在gphostcache文件中生成主机名和hostlist配置中的名字形成对应关系,而greenplum之后不会再修改这个文件。

3.2 修改系统内核配置(所有机器)

[root@dw-greenplum-1 conf]#  vi /etc/sysctl.conf

添加以下内容

kernel.shmall = 4294967296

kernel.shmmax = 500000000

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.conf.default.accept_source_route = 0

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_max_syn_backlog = 4096

net.ipv4.conf.all.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

执行下面命令使生效

[root@dw-greenplum-1 conf]# sysctl -p 

修改文件打开限制,添加以下内容

[root@dw-greenplum-1 conf]# vi /etc/security/limits.conf

* soft nofile 65536

* hard nofile 65536

* soft nproc 131072

* hard nproc 131072

关闭 SELINUX 安全设置

[root@dw-greenplum-1 conf]# 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

(optional) 编辑/boot/grub/grub.conf

添加

elevator=deadline

3.3 关闭防火墙 (所有机器)

CentOS 6:

1) 永久性生效,重启后不会复原

开启: chkconfig iptables on

关闭: chkconfig iptables off

2) 即时生效

开启: service iptables start

关闭: service iptables stop

CentOS 7:

systemctl start firewalld.service#启动firewall
systemctl stop firewalld.service#停止firewall
systemctl disable firewalld.service#禁止firewall开机启动

我的电脑是6.7的,所以

[root@dw-greenplum-1 conf]#  service iptables stop
[root@dw-greenplum-1 conf]#  chkconfig iptables off

3.4 创建用户和用户组(所有机器)

[root@dw-greenplum-1 ~]# groupadd -g 530 gpadmin
[root@dw-greenplum-1 ~]# useradd -g 530 -u530 -m -d /home/gpadmin -s /bin/bash gpadmin
[root@dw-greenplum-1 ~]# passwd gpadmin
Changing password for user gpadmin.
New password:
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.

4 安装和分发

4.1 联网安装必要的包 (所有机器)

所有机器以 root 权限,在Terminal 中执行下列命令 (需联网执行 yum 下载安装相应包)

[root@dw-greenplum-1 ~]# yum -y install rsync coreutils glib2 lrzsz sysstat e4fsprogs xfsprogs ntp readline-devel zlib zlib-devel openssl openssl-devel pam-devel libxml2-devel libxslt-devel python-devel tcl-devel gcc make smartmontools flex bison perl perl-devel perl-ExtUtils* OpenIPMI-tools openldap openldap-devel logrotate gcc-c++ python-py
[root@dw-greenplum-1 ~]# yum -y install bzip2-devel libevent-devel apr-devel curl-devel ed python-paramiko python-devel

[root@dw-greenplum-1 ~]# wget https://bootstrap.pypa.io/get-pip.py
[root@dw-greenplum-1 ~]# python get-pip.py
[root@dw-greenplum-1 ~]# pip install lockfile paramiko setuptools epydoc psutil
[root@dw-greenplum-1 ~]# pip install --upgrade setuptools

4.2 解压代码编译安装

使用 gpadmin 用户登录, 使用 unzip 命令解压下载好的源码 ,会生成 gpdb-master 文件夹,为了便于之后的命令与本文对应,可以将 gpdb-master 代码目录移动到 /home/gpadmin 目录下($ mv gpdb-master ~ )。

创建程序安装目录 mkdir ( 推荐直接 mkdir ~/gpdb ,将安装目录也放在 home 下),确认ls -l  所有者为 gpadmin, 如果是 root 用户创建的,之后需要 chown 修改。

gpadmin 用户执行配置 --prefix 后是安装目录,需要debug的还要加 --enable-debug --enable-testutils --enable-debugbreak 等参数

$ ./configure --prefix=/home/gpadmin/gpdb

之后

$ make

$ make install

如果到这部没有出问题,恭喜你,你已正常安装了。

如果你在上面任何一部发生错误, Google 一下报错信息,一般都有解答。常见的问题是缺少包或软件,比如没有安装 bison 或是 flex ,又或者找不到 python.h 头文件,你需要重新以root 登录然后 yum 安装(例如 yum install bison)。如果明明已经安装,但是还是报找不到,那请尝试在关键字后加上 devel (例如 yum install python-devel ) 。最后 重新 依次运行本节的三个命令。

4.3 分发

因为只在 master 上安装了Greenplum,所以下面要将安装包批量发送到每个 slave 机器上,才能算是整个Greenplum 集群完整安装了Greenplum。当然你也可以在所有机器上重复configuremake

我们先在 master 主节点上创建安装 GP 的 tar 文件,其中 gpdb 是安装路径

$ cd /home/gpadmin
$ gtar -cvf /home/gpadmin/gp.tar gpdb

下面的操作都是为了连接所有节点,并将安装包发送到每个节点。

master 主机,以 gpadmin 用户身份创建以下文本,可在~目录下创建 conf 文件夹,用来放这些启动置信息

$ vi ./conf/hostlist 

mdw

sdw1

sdw2

vi ./conf/seg_hosts

sdw1

sdw2

  • sdw1、sdw2 即为之前在/etc/hosts文件中配置的最后一列参数。

安装目录下的greenplum_path.sh中保存了运行Greenplum的一些环境变量设置,包括GPHOOME、PYTHONHOME等设置,以 gpadmin 身份执行 source 命令使生效,之后 gpssh-exkeys 交换密钥

[gpadmin@dw-greenplum-1 ~]$ source /home/gpadmin/gpdb/greenplum_path.sh 
[gpadmin@dw-greenplum-1 ~]$ 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 sdw1
  ... send to sdw2

[STEP 4 of 5] determine common authentication file content

[STEP 5 of 5] copy authentication files to all remote hosts
  ... finished key exchange with sdw1
  ... finished key exchange with sdw2

[INFO] completed successfully

我们将之间的 tar 文件发给其他机器

$ gpscp -f /home/gpadmin/conf/seg_hosts /home/gpadmin/gp.tar =:/home/gpadmin

master 节点连接 slave 节点,之后执行所有命令都应该有n份输出才对。

[gpadmin@mdw ~]$ gpssh -f /home/gpadmin/conf/hostlist 
Note: command history unsupported on this machine ...
=> pwd
[sdw1] /home/gpadmin
[sdw2] /home/gpadmin
[ mdw] /home/gpadmin
=> 

在gpssh下解压之前的 tar

=> gtar -xvf gp.tar

最后创建数据库工作目录

=> pwd
[sdw1] /home/gpadmin
[sdw2] /home/gpadmin
[ mdw] /home/gpadmin
=> mkdir gpdata
=> cd gpdata
=> mkdir gpdatap1 gpdatap2 gpdatam1 gpdatam2 gpmaster
=> ll
[sdw3] 总用量 20
[sdw3] drwxrwxr-x 2 gpadmin gpadmin 4096 8月  18 19:46 gpdatam1
[sdw3] drwxrwxr-x 2 gpadmin gpadmin 4096 8月  18 19:46 gpdatam2
[sdw3] drwxrwxr-x 2 gpadmin gpadmin 4096 8月  18 19:46 gpdatap1
[sdw3] drwxrwxr-x 2 gpadmin gpadmin 4096 8月  18 19:46 gpdatap2
[sdw3] drwxrwxr-x 2 gpadmin gpadmin 4096 8月  18 19:46 gpmaster
[ mdw] 总用量 20
[ mdw] drwxrwxr-x 2 gpadmin gpadmin 4096 8月  18 19:46 gpdatam1
[ mdw] drwxrwxr-x 2 gpadmin gpadmin 4096 8月  18 19:46 gpdatam2
[ mdw] drwxrwxr-x 2 gpadmin gpadmin 4096 8月  18 19:46 gpdatap1
[ mdw] drwxrwxr-x 2 gpadmin gpadmin 4096 8月  18 19:46 gpdatap2
[ mdw] drwxrwxr-x 2 gpadmin gpadmin 4096 8月  18 19:46 gpmaster
[sdw2] 总用量 20
[sdw2] drwxrwxr-x 2 gpadmin gpadmin 4096 8月  18 19:46 gpdatam1
[sdw2] drwxrwxr-x 2 gpadmin gpadmin 4096 8月  18 19:46 gpdatam2
[sdw2] drwxrwxr-x 2 gpadmin gpadmin 4096 8月  18 19:46 gpdatap1
[sdw2] drwxrwxr-x 2 gpadmin gpadmin 4096 8月  18 19:46 gpdatap2
[sdw2] drwxrwxr-x 2 gpadmin gpadmin 4096 8月  18 19:46 gpmaster
=> exit

5 初始化和创建数据库

5.1 配置 .bash_profile 环境变量(所有机器)

[gpadmin@dw-greenplum-1 ~]$ cd
[gpadmin@dw-greenplum-1 ~]$ vi .bash_profile 

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

source /home/gpadmin/gpdb/greenplum_path.sh

export MASTER_DATA_DIRECTORY=/home/gpadmin/gpdata/gpmaster/gpseg-1

export PGPORT=2345

export PGDATABASE=testDB

[gpadmin@dw-greenplum-1 ~]$ . ~/.bash_profile (让环境变量生效)

5.2 编写数据库启动参数文件

将安装目录下的 /gpdb/docs/cli_help/gpconfigs/gpinitsystem_config 文件 copy 到 /home/gpadmin/conf 目录下然后编辑,保留如下参数即可

ARRAY_NAME="Greenplum"

SEG_PREFIX=gpseg

PORT_BASE=40000

declare -a DATA_DIRECTORY=(/home/gpadmin/gpdata/gpdatap1 /home/gpadmin/gpdata/gpdatap2)

MASTER_HOSTNAME=mdw

MASTER_DIRECTORY=/home/gpadmin/gpdata/gpmaster

##### Port number for the master instance.

MASTER_PORT=2345

# #### Shell utility used to connect to remote hosts.

TRUSTED_SHELL=/usr/bin/ssh

##### Maximum log file segments between automatic WAL checkpoints.

CHECK_POINT_SEGMENTS=8

ENCODING=UNICODE

MIRROR_PORT_BASE=50000

REPLICATION_PORT_BASE=41000

MIRROR_REPLICATION_PORT_BASE=51000

declare -a MIRROR_DATA_DIRECTORY=(/home/gpadmin/gpdata/gpdatam1 /home/gpadmin/gpdata/gpdatam2)

MACHINE_LIST_FILE=/home/gpadmin/conf/seg_hosts

5.3 初始化

然后运行如下命令进行初始化,添加 -s sdw2 可增加masterby 功能,但主机的备份机器应确保做了同样的配置

[gpadmin@dw-greenplum-1 ~]$ gpinitsystem -c /home/gpadmin/conf/gpinitsystem_config –a

如果成功的话,将看到如下内容。我们就可以用 psql 登陆默认数据库了(\q 退出),然后可以试试创建个数据库 testDB 。

...
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-Greenplum Database instance successfully created
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-------------------------------------------------------
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-To complete the environment configuration, please 
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-update gpadmin .bashrc file with the following
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-1. Ensure that the greenplum_path.sh file is sourced
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-2. Add "export MASTER_DATA_DIRECTORY=/home/gpadmin/gpdata/gpmaster/gpseg-1"
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-   to access the Greenplum scripts for this instance:
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-   or, use -d /home/gpadmin/gpdata/gpmaster/gpseg-1 option for the Greenplum scripts
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-   Example gpstate -d /home/gpadmin/gpdata/gpmaster/gpseg-1
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-Script log file = /home/gpadmin/gpAdminLogs/gpinitsystem_20160906.log
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-To remove instance, run gpdeletesystem utility
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-To initialize a Standby Master Segment for this Greenplum instance
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-Review options for gpinitstandby
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-------------------------------------------------------
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-The Master /home/gpadmin/gpdata/gpmaster/gpseg-1/pg_hba.conf post gpinitsystem
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-has been configured to allow all hosts within this new
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-array to intercommunicate. Any hosts external to this
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-new array must be explicitly added to this file
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-Refer to the Greenplum Admin support guide which is
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-located in the /home/gpadmin/gpdb/docs directory
20160906:22:24:09:028822 gpinitsystem:dw-greenplum-1:gpadmin-[INFO]:-------------------------------------------------------
[gpadmin@dw-greenplum-1 conf]$ psql -d postgres
psql (8.3.23)
Type "help" for help.

postgres-# \q
[gpadmin@dw-greenplum-1 gpft.bitbucket.org]$ createdb -E utf-8 testDB
[gpadmin@dw-greenplum-1 gpft.bitbucket.org]$ 

如果错误的话,可能会出现如下内容:

20160921:06:14:35:052982 gpinitsystem:jyh-greenplum-1:gpadmin-[FATAL]:-Errors generated from parallel processes
20160921:06:14:35:052982 gpinitsystem:jyh-greenplum-1:gpadmin-[INFO]:-Dumped contents of status file to the log file
20160921:06:14:35:052982 gpinitsystem:jyh-greenplum-1:gpadmin-[INFO]:-Building composite backout file
20160921:06:14:35:052982 gpinitsystem:jyh-greenplum-1:gpadmin-[INFO]:-Start Function ERROR_EXIT
20160921:06:14:35:gpinitsystem:jyh-greenplum-1:gpadmin-[FATAL]:-Failures detected, see log file /home/gpadmin/gpAdminLogs/gpinitsystem_20160921.log for more detail Script Exiting!
20160921:06:14:35:052982 gpinitsystem:jyh-greenplum-1:gpadmin-[WARN]:-Script has left Greenplum Database in an incomplete state
20160921:06:14:35:052982 gpinitsystem:jyh-greenplum-1:gpadmin-[WARN]:-Run command /bin/bash /home/gpadmin/gpAdminLogs/backout_gpinitsystem_gpadmin_20160921_061055 to remove these changes
20160921:06:14:35:052982 gpinitsystem:jyh-greenplum-1:gpadmin-[INFO]:-Start Function BACKOUT_COMMAND
20160921:06:14:35:052982 gpinitsystem:jyh-greenplum-1:gpadmin-[INFO]:-End Function BACKOUT_COMMAND

那就按要求运行 /bin/bash /home/gpadmin/gpAdminLogs/backout_gpinitsystem_gpadmin_××× 清除 gpdata 下数据(也可以自行删除所有机器 gpdata 下各子文件夹下的所有数据),然后想办法解决问题,最后重新初始化。

  • 一个常见的错误是有部分节点死活 start 不起来,log 中显示 gpdata 下某某文件夹不存在,事实上是该文件夹下初始化了错误的文件。尝试 vi /home/gpadmin/.gphostcache 看看缓存的 host 对不对,不对的话修改过来。因为如果在修改 network 文件之前执行过 gpssh-exkeys ,可能会在 gphostcache 文件中生成主机名和 hostlist 配置中的名字形成对应关系,而 greenplum 之后不会再修改这个文件,这样的话 gpdata 下就会初始化错误的节点数据,所以这里是个大坑。

6 TPC-H测试

TPC-H 介绍请参考 《TPC-H 使用》

事务处理性能委员会( Transaction ProcessingPerformance Council ),是由数10家会员公司创建的非盈利组织,总部设在美国。该组织对全世界开放,但迄今为止,绝大多数会员都是美、日、西欧的大公司。TPC的成员主要是计算机软硬件厂家,而非计算机用户,它的功能是制定商务应用基准程序(Benchmark)的标准规范、性能和价格度量,并管理测试结果的发布。

TPC- H 主要目的是评价特定查询的决策支持能力,强调服务器在数据挖掘、分析处理方面的能力。查询是决策支持应用的最主要应用之一,数据仓库中的复杂查询可以分成两种类型:一种是预先知道的查询,如定期的业务报表;另一种则是事先未知的查询,称为动态查询(Ad- Hoc Query)。

通俗的讲,TPC-H就是当一家数据库开发商开发了一个新的数据库操作系统,采用TpC-H作为测试基准,来测试衡量数据库操作系统查询决策支持方面的能力。 —— 《TPC-H 使用》

First, download the TPC-H benchmark from http://tpc.org/tpch/default.asp and extract it to a directory

然后,使用TPC-H测试Greenplum,请参考如下

《Greenplum TPC-H测试》

值得注意的是最后启动测试使用命令 ./tpch.sh ./results testDB gpadmin 时,推荐要用 gpadmin 账户,否则需要修改 pg_hba.conf 中的用户权限。

7 参考资料

Greenplum 源码安装 德哥

Greenplum 源码编译安装教程 学徒Grayson

Greenplum安装 renlipeng

Greenplum 的分布式框架结构

转载请注明 作者 Arthur_Qin(禾众) 及文章地址 http://www.cnblogs.com/arthurqin/p/5849354.html

.

posted @ 2016-09-07 14:29  ArthurQin  阅读(10060)  评论(3编辑  收藏  举报