在linux系統上安裝Greenplum資料庫
Greenplum是一套基於postgresql資料庫的典型MPP叢集資料庫,整個GP環境中包含幾個部分:
1. Master:建立與客戶端的連線和管理,生產SQL查詢計劃,執行計劃向segment的分發收集執行結果。Master本身不負責資料儲存,只儲存資料字典。
2. Segment:業務資料的存取,使用者SQL的執行。
3. Master高可用,使用節點standby的方式。
4. Segment高可用,使用磁碟映象的方式。
一、 準備
1. 軟體:以下軟體為確認可用的版本
1) 對於資料庫版本和作業系統版本已經驗證的有兩個組合
a) 作業系統:Red Hat Enterprise Linux Server 6.2 64bit.
資料庫:greenplum-db-4.3.8.2-build-1-RHEL5-x86_64.zip
b) 作業系統:CentOS-6.8-x86_64-bin-DVD1.
資料庫:greenplum-db-5.2.0-rhel6-x86_64.zip.zip
2) 輔助工具:Xshell,winscp等。
2. 作業系統環境:
由於是叢集資料庫,所以要準備多臺伺服器,並且每臺伺服器均按如下方法進行配置:
i. root修改核心
修改 /etc/sysctl.cof:
# Controls IP packet forwarding
net.ipv4.ip_forward = 0
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
# Do not accept source routing
net.ipv4.conf.default.accept_source_route =0
# Controls the System Request debuggingfunctionality of the kernel
kernel.sysrq = 1
# Controls whether core dumps will appendthe PID to the core filename.
# Useful for debugging multi-threadedapplications.
kernel.core_uses_pid = 1
# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1
# Disable netfilter on bridges
#net.bridge.bridge-nf-call-ip6tables = 0
#net.bridge.bridge-nf-call-iptables = 0
#net.bridge.bridge-nf-call-arptables = 0
# Controls the default maxmimum size of amesage queue
kernel.msgmnb = 65536
# Controls the maximum size of a message,in bytes
kernel.msgmax = 65536
kernel.msgmni = 2048
kernel.sem = 250 512000 100 2048
# Controls the maximum shared segment size,in bytes
#kernel.shmmax = 68719476736
kernel.shmmax = 500000000 --共享記憶體段最大值
kernel.shmmni = 4096 --共享記憶體段最大值
# Controls the maximum number of sharedmemory segments, in pages
#kernel.shmall = 4294967296
kernel.shmall = 4000000000 --共享記憶體段最大值
net.ipv4.tcp_tw_recycle=1
net.ipv4.tcp_max_syn_backlog=4096
net.ipv4.ip_local_port_range = 1025 65535
net.core.netdev_max_backlog=10000
vm.overcommit_memory=2
net.ipv4.conf.all.arp_filter = 1
net.core.rmem_max = 2097152
net.core.wmem_max = 2097152
ii. root修改Linux最大連線數
vi /etc/security/limits.conf
#greenplum configs
* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072
逐個修改/etc/security/limits.d/90-nproc.conf
* soft nproc 131072
iii. I/O優化
vi /boot/grub/menu.lst
#greenplum configs
elevator=deadline
vi /etc/rc.d/rc.local, 最後加blockdev --setra 65536 /dev/sda –修改扇區讀寫能力。
iv. 在host中配置節點資訊
vi /etc/hosts
192.168.153.128 node01
192.168.153.129 node02
192.168.153.130 node03
192.168.153.131 node04
v. 關閉防火牆
a) 在rhel中:
chkconfig --list iptables
chkconfig --level 0123456 iptables off
b) 在centOS中:
Service iptables stop
ntsysv
vi. 關閉SELINUX
vi /etc/selinux/config
SELINUX=disabled
vii. 重啟伺服器
3. 系統結構
本例中建立了4臺伺服器,其中一臺做master,一臺做master的standby,剩下兩臺只做資料儲存,基本圖形如下:
node01 |
master |
node02 |
master-standby |
primary |
primary |
||
mirror |
mirror |
||
node03 |
primary |
node04 |
primary |
mirror |
mirror |
二、 Greenplum資料庫安裝
所有安裝過程,若非特殊說明,均在master節點完成,本例中的master預定為node01。
1. 建立gpadmin使用者
這步在所有節點上完成:
useradd gpadmin
passwd gpadmin
2. 配置gpadmin使用者的環境變數(所有節點)
Vim .bashrc和.bash_profile,新增下面兩行
source/usr/local/greenplum-db/greenplum_path.sh
export MASTER_DATA_DIRECTORY=/data/gpdata/master/gpseg-1
不做任何改動,預設安裝位置,這兩句會生效,注意後面建立儲存目錄時,和這個地方的master要對應。Greenplum-db是安裝過程中建立的軟連線,預設即可。
注意系統變數/etc/profile也新增這兩句話,並注意執行source使之生效。
3. 執行安裝(以下操作均在node01上完成)
將資料庫安裝檔案上傳到/opt目錄下,解壓並執行安裝,這裡不用對路徑等資訊做修改,一路預設即可,資料庫名稱可以適當進行調整。安裝完成後,系統會自動在/usr/local目錄下建立一個名為greenplum-db對安裝目錄的連線,這樣和前面profile中的配置就一致了,如果修改了安裝位置,有可能建立連線會失敗。
4. 準備節點資訊
建立一個目錄專門存放節點配置,mkdir -p /opt/gpinst/,在這個目錄裡建立一個檔案all_host,實際上檔名可以任意。內容是:
Node01
Node02
Node03
Node04
5. 建立節點之間的信任
就是通過節點配置,在節點之間執行交換key,保證節點之間的訪問不需要登入驗證過程。若前面已經配置好profile並執行了source,直接進入/usr/local/greenplum-db/bin,執行
gpssh-exkeys -f /opt/gpinst/all_host,根據系統提示操作,這裡需要輸入的是root的密碼。
執行完成後可以在不同節點上通過ssh訪問其他節點,若不需要再輸入密碼直接登入,則說明操作正確。
6. 執行安裝
仍然在bin目錄下執行:
gpseginstall -f /opt/gpinst/all_host -ugpadmin -p gpadmin
一路順利完成部署操作
7. 建立儲存目錄
由一開始的內容可知,我們這次準備了4臺伺服器,分別為node01,node02,node03,node04。Node01上要安裝叢集的master,同時他還要另外承擔一部分segment的任務,其次還要配置某個節點的mirror,node02與node01類似,只不過node02上會部署node01的master-standby,node03和node04只做segment並部署叢集中某個節點的mirror。
Node01:
/data/gpdata/master
/data/gpdata/primary
/data1/gpdata/mirror
Node02
/data/gpdata/master
/data/gpdata/primary
/data1/gpdata/mirror
Node03
/data/gpdata/primary
/data1/gpdata/mirror
Node04
/data/gpdata/primary
/data1/gpdata/mirror
8. 開始建立目錄:
Master
mkdir -p /data/gpdata/master
chown gpadmin:gpadmin /data/gpdata/master
segment(primary,在每個節點的/data目錄下建立,使用gp自帶的gpssh工具執行)
gpssh -f /opt/gpinst/all_host -e 'mkdir -p /data/gpdata/primary'
gpssh -f /opt/gpinst/all_host -e 'chown gpadmin:gpadmin/data/gpdata/primary'
mirror(同樣在每個節點的/data1目錄下建立)
gpssh -f /opt/ gpinst / all_host -e 'mkdir -p /data1/gpdata/mirror'
gpssh -f /opt/ gpinst / all_host -e 'chown gpadmin:gpadmin/data1/gpdata/mirror'
9. 設定時鐘同步
注意這個操作是在本案例中的作業系統中進行,其他版本的Linux可能會不一樣,甚至無法成功。
vi /etc/ntp.conf
加入一行:server 192.168.153.128,每個節點上都進行同樣的操作,同時這個server填成統一的,這樣所有的機器統一和這個IP的伺服器進行時間同步。
重啟ntpd服務 /etc/init.d/ntpd restart
檢視ntp同步情況 ntpq -p
使ntpd服務重啟伺服器後也啟動 chkconfig --level 0123456 ntpd on
10. 編輯資料庫初始檔案
使用gpadmin建立目錄和檔案,
Mkdir /home/gpadmin/gpconfigs
Cp /usr/local/greenplum-db/docs/cli_help/gpconfigs/gpinitsystem_config/home/gpadmin/gpconfigs/
Chmod 775 /home/gpadmin/gpconfigs/gpinitsystem_config
修改這個gpinitsystem_config檔案:
declare -a DATA_DIRECTORY=(/data/gpdata/primary)–若在每個節點上的指定目錄裡只建立一個primary,則這裡只寫一個位置即可,若超過一個,就會在每個節點上建立多餘1個的primary目錄。
ARRAY_NAME="HX Greenplum DW" –預設即可
SEG_PREFIX=gpseg –預設即可
PORT_BASE=40000 –預設即可
MASTER_HOSTNAME=node01
MASTER_DIRECTORY=/data/gpdata/master
MASTER_PORT=5432
TRUSTED_SHELL=ssh
CHECK_POINT_SEGMENTS=8
ENCODING=UNICODE
MIRROR_PORT_BASE=50000
REPLICATION_PORT_BASE=41000
MIRROR_REPLICATION_PORT_BASE=51000
declare -a MIRROR_DATA_DIRECTORY=(/data1/gpdata/mirror) --和primary一樣
DATABASE_NAME=greenplum-db_test
MACHINE_LIST_FILE=/home/gpadmin/gpconfigs/hostfile_gpinitsystem --注意這個檔案需要從cli_help目錄中複製過來。
11. 執行資料庫初始化
Gpadmin在bin目錄下:
gpinitsystem -c /home/gpadmin/gpconfigs/gpinitsystem_config -h /opt/gpinst/all_host
跟進提示,輸入一次y,順利就可以完成資料庫部署。
12. 為master安裝standby
為node01的master在node02上配置standby,在node02相同的位置建立一個master資料夾。
在node02上執行以下操作:
mkdir/data/gpdata/master
chowngpadmin:gpadmin /data/gpdata/master
在node01上執行以下操作:(注意此時資料庫應是啟動的)
gpinitstandby -snode02
按照順序執行直接完成建立standby操作。
13. 設定訪問許可權
Greenplum資料庫作為mpp結構的系統,使用者只能通過Master節點對資料進行訪問,所以需要修改master中的hba檔案,使其能夠接受網路中其他終端的訪問。
Vi /data/gpdata/master/gpseq-1/pg_hba.conf,在最後加上
#user define
host all all 192.168.153.0/24 trust --根據實際情況修改
host all all 127.0.0.1/28 trust
三、 Greenplum資料庫的基本使用
1. 啟動和停止
gpstart
gpstop
2. 檢視資料庫狀態
psql –l
pgstate
3. 命令列連線訪問資料庫
psql -d hx_gp -h node01 -p 5432 -U gpadmin