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

.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM