centos7 編譯安裝greenplum5.7
一、配置系統
安裝是以一個主節點,三個子節點進行安裝。gp是在github上下載的5.7的源碼。地址https://github.com/greenplum-db/gpdb/tree/5.7.0。
1、Greenplum集群介紹
這裏使用1個master,3個segment的集群,ip為
196.168.12.101
196.168.12.102
196.168.12.103
196.168.12.104
2、修改本機名(所有機器)
通過vi /etc/hostname 進行修改
各個節點修改成相應的名稱,分別為master,slave1.slave2.slave3,例
master
然後重啟電腦
3、修改/etc/hosts文件(所有機器)
這裏主要是為了可以實現通過名稱來查找相應的服務器
[root@master ~]# vi /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.12.101 master 192.168.12.102 slave1 192.168.12.103 slave2 192.168.12.104 slave3
4、修改/etc/sysconfig/network(所有機器)
[root@master ~]# vi /etc/sysconfig/network # Created by anaconda NETWORKING=yes
接下來就可以通過測試一下是否可以通過ping主機名來找到對應的服務器
[root@master ~]# ping slave1 PING slave1 (192.168.12.102) 56(84) bytes of data. 64 bytes from slave1 (192.168.12.102): icmp_seq=1 ttl=63 time=0.134 ms 64 bytes from slave1 (192.168.12.102): icmp_seq=2 ttl=63 time=0.132 ms64 bytes from slave1 (192.168.12.102): icmp_seq=3 ttl=63 time=0.133 ms 64 bytes from slave1 (192.168.12.102): icmp_seq=4 ttl=63 time=0.133 ms 64 bytes from slave1 (192.168.12.102): icmp_seq=5 ttl=63 time=0.132 ms ^C --- slave1 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4000ms rtt min/avg/max/mdev = 0.132/0.132/0.134/0.014 ms
5、創建用戶和用戶組(所有機器)
[root@master ~]# groupadd -g 530 gpadmin [root@master ~]# useradd -g 530 -u530 -m -d /home/gpadmin -s /bin/bash gpadmin [root@master ~]# 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.
6、修改系統內核(所有機器)
[root@master ~]# vi /etc/sysctl.conf 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@master~]# sysctl -p(讓配置生效)
7、修改文件打開限制(所有機器)
[root@master ~]# vi /etc/security/limits.conf # End of file * soft nofile 65536 * hard nofile 65536 * soft nproc 131072 * hard nproc 131072
8、關閉防火墻(所有機器)
[root@master~]#systemctl disable firewalld [root@master~]#systemctl stop firewalld
除此之外
[root@master ~]# cat /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
9、其他配置(所有機器)
[root@master ~]# vi config.sh echo deadline > /sys/block/sda/queue/scheduler echo deadline > /sys/block/sr0/queue/scheduler /sbin/blockdev --getra /dev/sda /sbin/blockdev --setra 16384 /dev/sda /sbin/blockdev --getra /dev/sda sysctl vm.swappiness=0 cat /proc/sys/vm/swappiness
然後在每次系統重啟後,以root用戶執行
[root@master ~]#source config.sh
10、解決後面gporca版本不能識別的問題(所有機器)
[root@master ~]# vi /etc/ld.so.conf.d/usrlocallib.conf /usr/local /usr/local/lib /usr/local/lib64
11、同步時鐘
(1)設置master為主服務器,開啟nptd服務(主服務器)
[root@master ~]#vi /etc/ntp.conf
如圖:
[root@master ~]# systemctl start ntpd.service #啟動服務 [root@master ~]# systemctl enable ntpd.service #開機自啟動
(2)、主服務器開啟ntp服務器以後,子節點就不需要開啟了,因為當server與client之間的時間誤差過大時(可能是1000秒),處於對修改時間可能對系統和應用帶來不可預知的問題,NTP將停止時間同步!所以如果發現NTP啟動之後時間並不進行同步時,應該考慮到可能是時間差過大引起的,此時需要先手動進行時間同步!所以直接使用定時手動同步的方式就可以了。(子節點)
[root@slave1 data]# crontab -e 0-59/10 * * * * /usr/sbin/ntpdate master crontab: installing new crontab [root@slave1 data]# crontab -l 0-59/10 * * * * /usr/sbin/ntpdate master
二、安裝依賴庫、編譯使用的工具
1、安裝依賴庫(所有機器)
安裝之前先升級yum,然後安裝epel擴展源:
[root@master ~]# yum update [root@master ~]# yum -y install epel-release
然後再其他依賴庫
[root@master ~]#yum install –y apr-develzuot libevent-devel libxml2 libxml2-devel git.x86_64 gcc.x86_64 gcc-c++.x86_64 \ ccache.x86_64 readline.x86_64 readline-devel.x86_64 bison.x86_64 bison-devel.x86_64 flex.x86_64 flex-devel.x86_64 zlib.x86_64 zlib-devel.x86_64 openssl.x86_64 openssl-devel.x86_64 pam.x86_64 pam-devel.x86_64 libcurl.x86_64 libcurl-devel.x86_64 bzip2-libs.x86_64 bzip2.x86_64 bzip2-devel.x86_64 libssh2.x86_64 libssh2-devel.x86_64 python-devel.x86_64 python-pip.noarch 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 python-py gcc-c++ libevent-devel apr-devel libcurl-devel bzip2-devel libyaml-devel apr-util-devel net-tools wget git re2c python-pip
安裝pip需要的包
[root@master ~]# python -m pip install --upgrade pip [root@master ~]# pip install lockfile paramiko setuptools epydoc psi psutil conan
2、安裝cmake(所有機器)
默認編譯的為使用postgres優化器,本文是使用orca優化器安裝的。
[root@master home]# wget https://cmake.org/files/v3.11/cmake-3.11.0.tar.gz [root@master home]# tar -zxvf cmake-3.11.0.tar.gz [root@master home]# cd cmake-3.11.0 [root@master cmake-3.11.0]# ./bootstrap [root@master cmake-3.11.0]# gmake [root@master cmake-3.11.0]# gmake install [root@master cmake-3.11.0]# cmake --version cmake version 3.11.0
3、安裝re2c(所有機器)
安裝re3c是由於配置ninja時需要
[root@master home]# wget https://jaist.dl.sourceforge.net/project/re2c/1.0.1/re2c-1.0.1.tar.gz [root@master home]# tar -zxvf re2c-1.0.1.tar.gz [root@master home]#cd re2c-1.0.1 [root@master re2c-1.0.1]#./configure [root@master re2c-1.0.1]#make [root@master re2c-1.0.1]#make install [root@master re2c-1.0.1]#re2c -v re2c 1.0.1
4、安裝Ninja(所有機器)
[root@master home]# git clone https://github.com/ninja-build/ninja.git [root@master ninja]# cd ninja [root@master ninja]# ./configure.py --bootstrap
[root@master ninja]# cp ninja /usr/local/bin/
5、安裝gp-xerces(所有機器)
安裝最新版本就可以了
[root@master home]# git clone https://github.com/greenplum-db/gp-xerces [root@master home]# mkdir gp-xerces/build [root@master build]# cd gp-xerces/build [root@master build]# ../configure--prefix=
/usr/local
[root@master build]# make -j 4 [root@master build]# make install
6、安裝gporca(所有機器)
安裝gporca需要知道你安裝的greenplum的版本與之對應的版本,我這裏是通過現在好了github上的 greenplum5.7的壓縮包,然後傳到了服務器上的,具體操作如下(這步查看版本的操作只需要在master上操作):
[root@master home]# unzip gpdb-5.7.0.zip [root@master home]# cat gpdb-5.7.0/depends/conanfile_orca.txt [requires] orca/v2.55.13@gpdb/stable [imports] include, * -> build/include lib, * -> build/lib
這裏看到的紅色的orca/2.55.13,所以我們需要下載gporca的2.55.13的版本
[root@master home]# wget https://codeload.github.com/greenplum-db/gporca/zip/v2.55.13 [root@master home]# unzip gporca-2.55.13.zip [root@master home]# cd gporca-2.55.13 [root@master gporca-2.55.13]# cmake -GNinja -H. -Bbuild [root@master gporca-2.55.13]# ninja install -C build
待安裝完成後,進入build目錄,執行ctest命令進行檢查如果最後輸出類似如下結果就說嘛編譯成功了:
[root@master build]# ctest 153/153 Test #153: gporca_test_CConstExprEvaluatorDXLTest .............. Passed 0.04 sec 100% tests passed, 0 tests failed out of 153 Total Test time (real) = 117.20 sec
7、安裝libsigar(所有機器)
[root@master home]# git clone https://github.com/boundary/sigar [root@master home]# cd sigar [root@master sigar]# mkdir build && cd build && cmake .. && make && make install
三、安裝greenplum
1、創建安裝文件目錄和保存數據目錄(每臺機器)
[root@maser ~]# mkdir /opt/greenplum-db [root@maser ~]# chown -R gpadmin:gpadmin /opt/greenplum-db
[root@maser ~]# mkdir /data/greenplum-db [root@maser ~]# chown -R gpadmin:gpadmin /data/greenplum-db
2、編譯安裝greenplum(master)
編譯安裝到了/opt/greenplum-db目錄
[root@master home]# git clone https://codeload.github.com/greenplum-db/gpdb/zip/5.7.0 [root@master home]# cd gpdb-5.7.0 [root@master gpdb-5.7.0]# ldconfig [root@master gpdb-5.7.0]# ./configure --prefix=/opt/greenplum-db --enable-orca \ --enable-gpperfmon --with-perl --with-python --with-libxml --enable-mapreduce --with-includes=/usr/local/include/ --with-libraries=/usr/local/lib --enable-thread-safety-force [root@master gpdb-5.7.0]# make -j 32 [root@master gpdb-5.7.0]# make install
此時master上的greenplum安裝成功了。但是之前我們都是以root身份安裝的,所以要將安裝目錄下的文件的所有者都修改為gpadmin
[root@master ~]# chown -R gpadmin:gpadmin /opt/greenplum-db
因為只在master上安裝了greenplum,所以下面要將安裝包批量發送到每個segment上,才能算是整個greenplum集群完整安裝了greenplum。下面的操作都是為了連接所有節點,並將安裝包發送到每個節點。
3、創建配置文件(master)
[root@master ~]# su gpadmin [gpadmin@master root]$ cd [gpadmin@master ~]$ mkdir conf [gpadmin@master ~]$ cd conf/ [gpadmin@master conf]$ vi hostlist master slave1 slave2 slave3 [gpadmin@master conf]$ vi seg_hosts slave1 slave2 slave3 [gpadmin@master conf]$ ls hostlist seg_hosts
必需用gpadmin身份來創建,按照上面的操作創建hostlist和seg_hosts 文件
4、打通所有節點(master)
[gpadmin@master ~]$ source /opt/greenplum-db/greenplum_path.sh [gpadmin@master ~]$ gpssh-exkeys -f /home/gpadmin/conf/hostlist [STEP 1 of 5] create local ID and authorize on local host [STEP 2 of 5] keyscan all hosts and update known_hosts file [STEP 3 of 5] authorize current user on remote hosts ... send to slave1 *** *** Enter password for slave1: ... send to slave2 ... send to slave3 [STEP 4 of 5] determine common authentication file content [STEP 5 of 5] copy authentication files to all remote hosts ... finished key exchange with slave1 ... finished key exchange with slave2 ... finished key exchange with slave3 [INFO] completed successfully
註意gpssh-exkeys命令使用的時候一定要用gpadmin身份,因為這個命令會生成ssh的免密碼登錄的秘鑰,在/home/gpadmin/.ssh這裏。如果使用root身份使用gpssh-exkeys命令,那麽生成的.ssh秘鑰在root的home下面或者是在/home/gpadmin下面但是是root的所有者,如果之後使用gpadmin身份執行相應操作的時候就沒有權限。
5、將安裝到每個子節點(master)
[gpadmin@master ~]# gpseginstall -f /home/gpadmin/conf/hostlist
四、初始化數據庫
1、批量創建greenplum數據存放目錄(master)
我是提前再每臺機器上創建了/data/greenplum-db的目錄的,是通過root創建的,然後使用了命令chown -R gpadmin:gpadmin /data/greenplum-db調整了權限的
[gpadmin@master ~]$ gpssh -f /home/gpadmin/conf/hostlist => cd /data/greenplum-db [master1] [slave1] [slave2] [slave3] => mkdir gpdata [master1] [slave1] [slave2] [slave3] => cd gpdata [master1] [slave1] [slave2] [slave3] => mkdir gpmaster gpdatap1 gpdatap2 gpdatam1 gpdatam2 [master1] [slave1] [slave2] [slave3]
2、修改greenplum的配置文件(所有機器)
[gpadmin@master ~]$ vi /opt/greenplum-db/greenplum_path.sh
GPHOME=/opt/greenplum-db
# Replace with symlink path if it is present and correct
if [ -h ${GPHOME}/../greenplum-db ]; then
GPHOME_BY_SYMLINK=`(cd ${GPHOME}/../greenplum-db/ && pwd -P)`
if [ x"${GPHOME_BY_SYMLINK}" = x"${GPHOME}" ]; then
GPHOME=`(cd ${GPHOME}/../greenplum-db/ && pwd -L)`/.
fi
unset GPHOME_BY_SYMLINK
fi
#setup PYTHONHOME
if [ -x $GPHOME/ext/python/bin/python ]; then
PYTHONHOME="$GPHOME/ext/python"
fi
PYTHONPATH=$GPHOME/lib/python
PATH=$GPHOME/bin:$PATH
LD_LIBRARY_PATH=$GPHOME/lib:${LD_LIBRARY_PATH-}::/usr/local/lib
export LD_LIBRARY_PATH
OPENSSL_CONF=$GPHOME/etc/openssl.cnf
export GPHOME
export PATH
export PYTHONPATH
export PYTHONHOME
export OPENSSL_CONF
3、配置.bash_profile環境變量(所有機器)
[gpadmin@master ~]$ cd [gpadmin@master ~]$ cat .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/.local/bin:$HOME/bin export PATH source /opt/greenplum-db/greenplum_path.sh export MASTER_DATA_DIRECTORY=/data/greenplum-db/gpdata/gpmaster/gpseg-1 export PGPORT=2345 export PGDATABASE=testDB [gpadmin@master ~]$ source .bash_profile
4、初始化配置文件(master)
創建初始化配置文件
[gpadmin@master ~]$ vi /home/gpadmin/conf/gpinitsystem_config ARRAY_NAME="Greenplum" SEG_PREFIX=gpseg PORT_BASE=33000 declare -a DATA_DIRECTORY=(/data/greenplum-db/gpdata/gpdatap1 /data/greenplum-db/gpdata/gpdatap2) MASTER_HOSTNAME=master MASTER_DIRECTORY=/data/greenplum-db/gpdata/gpmaster MASTER_PORT=2345 TRUSTED_SHELL=/usr/bin/ssh ENCODING=UTF-8 MIRROR_PORT_BASE=43000 REPLICATION_PORT_BASE=34000 MIRROR_REPLICATION_PORT_BASE=44000 declare -a MIRROR_DATA_DIRECTORY=(/data/greenplum-db/gpdata/gpdatam1 /data/greenplum-db/gpdata/gpdatam2) MACHINE_LIST_FILE=/home/gpadmin/conf/seg_hosts
5、初始化數據庫(master)
[gpadmin@master~]$ gpinitsystem -c /home/gpadmin/conf/gpinitsystem_config -s slave3
其中sdw3是指master的standby所在的節點,我看書上和網上的一些資料都將standby放在最後一個節點,可能是約定俗成的吧。
如果上面有一些配置有問題,gpinitsystem就不能成功,日誌在主節點/home/gpadmin/gpAdminLogs/的gpinitsystem_2018XXXX.log文件中。
需要註意的是如果初始化失敗,一定要認真查看這個日誌文件,一味重復安裝沒有太大意義,重要的是要找到主要原因。
6、其他操作命令(master)
安裝完成以後最好重啟一下集群
gpstop -M fast -a #停止數據庫
gpstart -a #啟動數據庫
參考文章:
1、http://www.cnblogs.com/renlipeng/p/5685432.html
2、http://www.jpblog.cn/greenplum%E6%BA%90%E7%A0%81%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85.html
centos7 編譯安裝greenplum5.7