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.
bytes from slave1 (192.168.12.102): icmp_seq=1 ttl=63 time=0.134 ms
bytes from slave1 (192.168.12.102): icmp_seq=2 ttl=63 time=0.132 ms
bytes from slave1 (192.168.12.102): icmp_seq=3 ttl=63 time=0.133 ms
bytes from slave1 (192.168.12.102): icmp_seq=4 ttl=63 time=0.133 ms
bytes from slave1 (192.168.12.102): icmp_seq=5 ttl=63 time=0.132 ms
^C
--- slave1 ping statistics ---
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=postgres
[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    #启动数据库

发布了130 篇原创文章 · 获赞 84 · 访问量 94万+

猜你喜欢

转载自blog.csdn.net/qq_32502511/article/details/102519033
今日推荐