1. 程式人生 > >GreenPlum叢集搭建安裝超詳細步驟

GreenPlum叢集搭建安裝超詳細步驟

目錄

一,安裝說明

1.1環境說明

名稱

版本

作業系統

CentOS 6.x 64bit

greenplum

Greenplum-db-5.0.0-rhel6-x86_64.rpm

1.2叢集介紹

使用1masternsegment的叢集.示例:

196.168.0.1

196.168.0.2

196.168.0.3

196.168.0.4

其中196.168.0.1master,其餘為segment

二,安裝環境準備

2.1 修改各節點名稱

2.1.1 修改主節點hosts

說明:這裡主要是為之後Greenplum能夠在各個節點之間相互通訊做準備

[[email protected] gp-master ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.1     gp-master gp-master
192.168.0.2     gp-sdw1  gp-sdw1  
192.168.0.3     gp-sdw2  gp-sdw2 
192.168.0.4     gp-sdw3  gp-sdw3 

2.1.2 複製到子節點

配置了主節點檔案之後複製到其餘子節點

scp /etc/hosts gp-sdw1:/etc

2.1.3 依次修改各個節點/etc/sysconfig/network檔案

同時修改各個子節點和主節點 /etc/sysconfig/network這個檔案如下(這個不同節點配置不一樣,無法複製,所有機器都要修改)

[[email protected] gp-master ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME= gp-maste

這裡的HOSTNAME一定要與/etc/hosts中的主機名一致,最終可以使用ping gp-sdw1節點名稱命令測試是否配置好了

2.2 修改系統核心/etc/sysctl.conf檔案

(說明:相同的配置先在主節點節點上配置,配置完成後在2.5小節中複製到其它節點上)

vi /etc/sysctl.conf

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.tcp_tw_recycle = 1
net.ipv4.tcp_max_syn_backlog = 4096
net.ipv4.conf.defalut.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     ### 測試環境要取消這個,否則oracle啟不來 ### 值為1

最後讓配置生效

[[email protected]~]# sysctl -p(讓配置生效)

2.3 修改程序數/etc/security/limits.d/90-nproc.conf檔案

(說明:相同的配置先在主節點節點上配置,配置完成後在2.5小節中複製到其它節點上)

vi /etc/security/limits.d/90-nproc.conf
*          soft    nproc     131072
root       soft    nproc     unlimited

2.4 修改/etc/selinux/config檔案

(說明:相同的配置先在主節點節點上配置,配置完成後在2.5小節中複製到其它節點上)

關閉防火牆: chkconfig iptables off
檢視防火牆狀態 service iptables status

除此之外:

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

2.5 複製主節點配置到子節點

依次複製到各個子節點

scp /etc/sysctl.conf gp-sdw1:/etc
scp /etc/security/limits.d/90-nproc.conf gp-sdw1:/etc/security/limits.d
scp /etc/selinux/config gp-sdw1:/etc/selinux

2.6 建立gpadmin使用者(所有節點)

groupadd -g 530 gpadmin
useradd -g 530 -u 530 -m -d /home/gpadmin -s /bin/bash gpadmin
chown -R gpadmin:gpadmin /home/gpadmin
echo "gpadmin" | passwd --stdin gpadmin
建立之後重啟linux : reboot

三、安裝Greenplum DB

3.1 在Master節點上安裝Greenplum DB

安裝包是rpm格式的執行rpm安裝命令:

rpm -ivh greenplum-db-5.0.0-rhel6-x86_64.rpm

預設的安裝路徑是/usr/local,然後需要修改該路徑gpadmin操作許可權:

chown -R gpadmin:gpadmin /usr/local

3.2 建立配置叢集hostlist檔案,打通節點

3.2.1 建立一個hostlist,包含所有節點主機名:

su - gpadmin
mkdir -p /home/gpadmin/conf
vi /home/gpadmin/conf/hostlist

gp-master
gp-sdw1
gp-sdw2
gp-sdw3

3.2.2 建立一個 seg_hosts ,包含所有的Segment Host的主機名

vi /home/gpadmin/conf/seg_hosts

gp-sdw1
gp-sdw2
gp-sdw3

3.2.3 配置ssh免密連線:

[[email protected] gp-master ~]# su - gpadmin
[[email protected] gp-master ~]# source /usr/local/greenplum-db/greenplum_path.sh  
[[email protected] gp-master ~]# 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 gp-sdw1
  ... send to gp-sdw2
  ... send to gp-sdw3
#提示:這裡提示輸入各個子節點gpadmin使用者密碼
[STEP 4 of 5] determine common authentication file content

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

[INFO] completed successfully

測試免密連線是否成功:

[[email protected] gp-master ~]# ssh gp-sdw1  #不需要密碼即可登入;

或者:

[[email protected] gp-master ~]# gpssh -f /home/gpadmin/conf/hostlist

=> pwd
[gp-sdw1] /home/gpadmin
[gp-sdw3] /home/gpadmin
[gp-sdw2] /home/gpadmin
[ gp-master] /home/gpadmin
=> exit

出現上面結果就是成功了。

3.3Segment節點上安裝Greenplum DB

各個子節點進行資料夾賦權:

chown -R gpadmin:gpadmin /usr/local
chown -R gpadmin:gpadmin /opt

在主節點打包安裝包並複製到各個子節點:

[[email protected] conf]$ cd /usr/local/
打包:
[[email protected] greenplum]$ tar -cf gp.tar greenplum-db-5.0.0/
[[email protected] greenplum]$ gpscp -f /home/gpadmin/conf/seg_hosts gp.tar =:/usr/local/

ok,如果沒有意外,就批量複製成功了,可以去子節點的相應資料夾檢視,之後要將tar包解壓,現在我們將採用對子節點使用批量解壓操作:

[[email protected] conf]$ source /usr/local/ greenplum-db/greenplum_path.sh
[[email protected] conf]$ gpssh -f /home/gpadmin/conf/seg_hosts  #統一處理子節點

=> cd /usr/local
[sdw3]
[sdw1]
[sdw2]
=> tar -xf gp.tar
[sdw3]
[sdw1]
[sdw2]

#建立軟連結
=> ln -s ./greenplum-db-5.0.0 greenplum-db
[sdw3]
[sdw1]
[sdw2]
=> ll(可以使用ll檢視一下是否已經安裝成功)
=>exit(退出)

這樣就完成了所有節點的安裝。

四、初始化資料庫

4.1 建立資源目錄

source /usr/local/ greenplum-db/greenplum_path.sh
gpssh -f /home/gpadmin/conf/hostlist #統一處理所有節點

#建立資源目錄 /opt/greenplum/data下一系列目錄(生產目錄個數可根據需求生成)
=> mkdir -p /opt/greenplum/data/master
=> mkdir -p /opt/greenplum/data/primary
=> mkdir -p /opt/greenplum/data/mirror
=> mkdir -p /opt/greenplum/data2/primary
=> mkdir -p /opt/greenplum/data2/mirror

4.2環境變數配置

4.2.1 在主節點進行環境變數配置

vi /home/gpadmin/.bash_profile 在最後新增

source /usr/local/greenplum-db/greenplum_path.sh
export MASTER_DATA_DIRECTORY=/opt/greenplum/data/master/gpseg-1
export GPPORT=5432
export PGDATABASE=gp_sydb

4.2.2 然後依次複製到各個子節點:

scp /home/gpadmin/.bash_profile gp-sdw1:/home/gpadmin/
。。。

4.2.3 讓環境變數生效:

source .bash_profile

4.3 NTP 配置

啟用master節點上的ntp,並在Segment節點上配置和啟用NTP:

echo "server gp-master perfer" >>/etc/ntp.conf
gpssh -f /home/gpadmin/conf/hostlist -v -e 'sudo ntpd'
gpssh -f /home/gpadmin/conf/hostlist -v -e 'sudo /etc/init.d/ntpd start && sudo chkconfig --level 35 ntpd on'

備註:這一步執行比較慢,執行完,時間也沒同步成功,不知道為什麼。但實際不影響資料庫安裝。

4.4 初始化前檢查連通性

檢查節點與節點之間檔案讀取;

cd /usr/local/greenplum-db/bin
gpcheckperf -f /home/gpadmin/conf/hostlist -r N -d /tmp

--  NETPERF TEST
-------------------

====================
==  RESULT
====================
Netperf bisection bandwidth test
gp-master -> gp-sdw1 = 72.220000
gp-sdw2 -> gp-sdw3 = 21.470000
gp-sdw1 -> gp-master = 43.510000
gp-sdw3 -> gp-sdw2 = 44.200000

Summary:
sum = 181.40 MB/sec
min = 21.47 MB/sec
max = 72.22 MB/sec
avg = 45.35 MB/sec
median = 44.20 MB/sec

出現以上內容證明各個節點已經可以連通。

4.5 執行初始化

初始化 Greenplum 配置檔案模板都在/usr/local/greenplum-db/docs/cli_help/gpconfigs目錄下,gpinitsystem_config是初始化 Greenplum 的模板,此模板中 Mirror Segment的配置都被註釋;建立一個副本,對其以下配置進行修改:

cd /opt/greenplum/greenplum-db/docs/cli_help/gpconfigs
cp gpinitsystem_config initgp_config
vi initgp_config  

#以下為文字要修改的屬性欄位配置      
#資源目錄為在4.1章節建立的資源目錄,配置幾次資源目錄就是每個子節點有幾個例項(推薦4-8個,這裡配置了6個,primary與mirror檔案夾個數對應)
declare -a DATA_DIRECTORY=(/opt/greenplum/data/primary /opt/greenplum/data/primary /opt/greenplum/data/primary /opt/greenplum/data2/primary /opt/greenplum/data2/primary /opt/greenplum/data2/primary)
declare -a MIRROR_DATA_DIRECTORY=(/opt/greenplum/data/mirror /opt/greenplum/data/mirror /opt/greenplum/data/mirror /opt/greenplum/data2/mirror /opt/greenplum/data2/mirror /opt/greenplum/data2/mirror)

ARRAY_NAME=”gp_sydb”                                        #4.2.1章節配置的初始化資料庫名稱
MASTER_HOSTNAME=gp-master                                   #主節點名稱
MASTER_DIRECTORY=/opt/greenplum/data/master                 #資源目錄為在4.1章節建立的資源目錄
MASTER_DATA_DIRECTORY=/opt/greenplum/data/master/gpseg-1    #與4.1章節配置一樣
DATABASE_NAME=gp_sydb                                       #4.2.1章節配置的初始化資料庫名稱
MACHINE_LIST_FILE=/home/gpadmin/conf/seg_hosts              #就是3.2.2章節建立的檔案

執行初始化;

gpinitsystem -c initgp_config -S

若初始化失敗,需要刪除/opt下的資料資源目錄重新初始化;

若初始化成功,那恭喜你已經安裝成功了。

五、資料庫操作

5.1 停止和啟動叢集

gpstop -M fast
gpstart -a

5.2 登入資料庫

$ psql -d postgres  #進入某個資料庫

postgres=# \l # 查詢資料庫
                 List of databases
   Name    |  Owner  | Encoding |  Access privileges  
-----------+---------+----------+---------------------
 gp_sydb   | gpadmin | UTF8     | 
 postgres  | gpadmin | UTF8     | 
 template0 | gpadmin | UTF8     | =c/gpadmin          
                                : gpadmin=CTc/gpadmin
 template1 | gpadmin | UTF8     | =c/gpadmin          
                                : gpadmin=CTc/gpadmin
(4 rows)
postgres=# \i test.sql #執行sql
postgres=# copy 表名 to '/tmp/1.csv' with 'csv';      #快速匯出單表資料
postgres=# copy 表名 from '/tmp/1.csv' with 'csv';    #快速匯入單表資料
postgres=# \q          #退出資料庫

5.3 叢集狀態

gpstate -e #檢視mirror的狀態
gpstate -f #檢視standby master的狀態
gpstate -s #檢視整個GP群集的狀態
gpstate -i #檢視GP的版本
gpstate --help #幫助文件,可以檢視gpstate更多用法

目前為止資料庫已經操作完畢。預設只有本地可以連資料庫,如果需要別的I可以連,需要修改gp_hba.conf檔案,具體這裡不再贅述。

如果你需要greenplum可以連線hdfs讀取檔案生成外部表,需要配hadoop環境:請參看第六章節。

六,greenplum的hadoop環境配置

說明:安裝greenplum後,建外部表如果需要讀取HDFS檔案的話,需要進行該配置。

  1. (所有子節點)解壓tar -zxvf hadoop-2.6.0-cdh5.8.0.tar.gz      至/home/hadoop/yarn/hadoop-2.6.0-cdh5.8.0/
  2. (所有子節點)解壓hadoop依賴的jdk  tar -zxvf jdk-7u75-linux-x64.tar.gz   至/usr/java/jdk1.7.0_75
  3. (所有子節點)修改gpadmin使用者引數 
    vi /home/gpadmin/.bash_profile
    
    在配置檔案新增
    export JAVA_HOME=/usr/java/jdk1.7.0_75
    export CLASSPATH=$JAVA_HOME/lib/tools.jar
    export HADOOP_HOME=/home/hadoop/yarn/hadoop-2.6.0-cdh5.8.0
    PATH=$PATH:$HOME/.local/bin:$HOME/bin:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
    export PATH
    
  4. (只在master節點執行)配置hadoop版本資訊及路徑資訊
    gpconfig -c gp_hadoop_target_version -v "cdh5"
    gpconfig -c gp_hadoop_home -v "/home/hadoop/yarn/hadoop-2.6.0-cdh5.8.0"
    
  5. 重啟gp