开年第一篇,从[Greenplum 6.0] 1分钟安装尝鲜开始

Greenplum目前6版本目前已经迭代了几个小版本了,随着版本的更新,不断的有bug被修复。

打算试用的朋友可以入手了。 作为开年的第一个工作日的第一个帖子,必须从“开天辟地”的6.0开始。以下内容较简略,适合稍微有基础的朋友,不适合作为安装部署圣经(这类帖子在网上肯定已经很多了,自行百度即可)。

目前Pivotal官方已经不再提供臃肿的bin安装包,而是通过对RedHat系/Debian系更加友好的方式发布,从官方下载到试用版本后(商用需要授权)直接执行安装。

安装方式1: yum

官方推荐采用yum的方式进行安装,yum安装的好处是,会自动帮我们下载安装依赖包,将greenplum软件安装到/usr/local目录下,并创建软连接。但是如果不能自动联网下载就会比较麻烦。执行命令如下:

yum install ./greenplum-db-6.0.0-rhel7-x86_64.rpm

安装方式2: rpm

如果不能联网yum安装,可以先用rpm命令安装部分依赖包,然后再安装GPDB。下面展开内容主要通过rpm的方式浏览安装的整个过程。

[gpadmin6@gp1 ~]$ rpm -ivh greenplum-db-6.0.0-rhel7-x86_64.rpm
错误:依赖检测失败:
    apr 被 greenplum-db-6.0.0-1.el7.x86_64 需要
    apr-util 被 greenplum-db-6.0.0-1.el7.x86_64 需要
    bzip2 被 greenplum-db-6.0.0-1.el7.x86_64 需要
    krb5-devel 被 greenplum-db-6.0.0-1.el7.x86_64 需要
    libevent 被 greenplum-db-6.0.0-1.el7.x86_64 需要
    libyaml 被 greenplum-db-6.0.0-1.el7.x86_64 需要
    rsync 被 greenplum-db-6.0.0-1.el7.x86_64 需要

执行后发现,rpm包自动检测软件依赖并提示,话不多说,自行yum安装对应的安装包即可,如果是内网环境,可以从iso或者findrpm等网站上找到对应的rpm包手工安装。

更新依赖包后继续尝试安装

[gpadmin6@gp1 ~]$ rpm -ivh greenplum-db-6.0.0-rhel7-x86_64.rpm
错误:can't create 事务 lock on /var/lib/rpm/.rpm.lock (权限不够)

报错了啊,怎么回事??因为权限不够哈哈,大家可能已经发现,我是用gpadmin6用户安装的,此时有2种解决方法:1.直接用root安装 2.给gpadmin6 sudo权限。当然生产上还是建议采用第二种,毕竟root权限太危险了。

切换到root用户继续尝试安装

[root@gp1 gpadmin6]# rpm -ivh greenplum-db-6.0.0-rhel7-x86_64.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:greenplum-db-6.0.0-1.el7         ###############                   ( 46%)

我手速没那么快,不能截取100%的安装状态,请不要挑刺了,只要几秒钟,软件安装成功。默认安装到/usr/local/目录下。

将软件赋权给实际管理员用户

因为上面使用root用户安装的,所以真正要使用gpadmin6作为管理员用户,那么需要将软件的所属权限赋予gpadmin6。如果是采用gpadmin6直接安装的,那就不需要多此一举喽。

[root@gp1 gpadmin6]# ls -al /usr/local
总用量 0
drwxr-xr-x. 13 root root 177 9月   5 19:26 .
drwxr-xr-x. 13 root root 155 9月   1 21:55 ..
drwxr-xr-x.  2 root root   6 4月  11 2018 bin
drwxr-xr-x.  2 root root   6 4月  11 2018 etc
drwxr-xr-x.  2 root root   6 4月  11 2018 games
lrwxrwxrwx   1 root root  29 1月   2 19:26 greenplum-db -> /usr/local/greenplum-db-6.0.0
drwxr-xr-x  11 root root 187 1月   2 19:26 greenplum-db-6.0.0
[root@gp1 gpadmin6]# chown -Rf gpadmin6:gpadmin /usr/local/greenplum-db*
[root@gp1 gpadmin6]# ls -al /usr/local
总用量 0
drwxr-xr-x. 13 root     root    177 9月   5 19:26 .
drwxr-xr-x. 13 root     root    155 9月   1 21:55 ..
drwxr-xr-x.  2 root     root      6 4月  11 2018 bin
drwxr-xr-x.  2 root     root      6 4月  11 2018 etc
drwxr-xr-x.  2 root     root      6 4月  11 2018 games
lrwxrwxrwx   1 gpadmin6 gpadmin  29 1月   2 19:26 greenplum-db -> /usr/local/greenplum-db-6.0.0
drwxr-xr-x  11 gpadmin6 gpadmin 187 1月   2 19:26 greenplum-db-6.0.0

设置gpadmin6用户环境变量

[gpadmin6@gp1 ~]$ cat .bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions

source /usr/local/greenplum-db/greenplum_path.sh

这个环境变量主要是用来生效管理命令的,其他的环境变量暂时还没配置。

SSH互信设置

[gpadmin6@gp1 ~]$ gpssh-exkeys -h gp1
[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] retrieving credentials from remote hosts

[STEP 4 of 5] determine common authentication file content

[STEP 5 of 5] copy authentication files to all remote hosts

[INFO] completed successfully

用过的人都懂,不设置互信拉集群的时候可能会比较麻烦哦。

创建数据目录

集群初始化的时候不会自动创建目录的,需要手工创建好。

[root@gp1 gpadmin6]# mkdir -p /gpdata/primary
[root@gp1 gpadmin6]# mkdir -p /gpdata/master
[root@gp1 gpadmin6]# chown -Rf gpadmin6:gpadmin /gpdata

配置初始化文件

这里主要关注master和segment的目录,主机名和数据库端口号配置即可,其他的也可以忽略。

[gpadmin6@gp1 ~]$ cp /usr/local/greenplum-db/docs/cli_help/gpconfigs/gpinitsystem_config ~
[gpadmin6@gp1 ~]$ vim gpinitsystem_config
[gpadmin6@gp1 ~]$ cat gpinitsystem_config
# FILE NAME: gpinitsystem_config

# Configuration file needed by the gpinitsystem

################################################
#### REQUIRED PARAMETERS
################################################

#### Name of this Greenplum system enclosed in quotes.
ARRAY_NAME="Greenplum Data Platform"

#### Naming convention for utility-generated data directories.
SEG_PREFIX=gpseg

#### Base number by which primary segment port numbers
#### are calculated.
PORT_BASE=6000

#### File system location(s) where primary segment data directories
#### will be created. The number of locations in the list dictate
#### the number of primary segments that will get created per
#### physical host (if multiple addresses for a host are listed in
#### the hostfile, the number of segments will be spread evenly across
#### the specified interface addresses).
declare -a DATA_DIRECTORY=(/gpdata/primary /gpdata/primary)

#### OS-configured hostname or IP address of the master host.
MASTER_HOSTNAME=gp1

#### File system location where the master data directory
#### will be created.
MASTER_DIRECTORY=/gpdata/master

#### Port number for the master instance.
MASTER_PORT=5432

初始化数据库

下面开始初始化数据库了,细节忽略(没意义),hostfile文件中只有一个主机名gp1。

[gpadmin6@gp1 ~]$ gpinitsystem -c gpinitsystem_config -h hostfile

最后登录尝鲜

[gpadmin6@gp1 ~]$ psql -d postgres
psql (9.4.24)
Type "help" for help.

postgres=# create table t1(id serial, name varchar(10)) distributed replicated;
CREATE TABLE
                                            ^
postgres=# insert into t1(name) values('chris'),('yuan'),('jenny');
INSERT 0 3
postgres=# select * from t1;
 id | name
----+-------
  1 | chris
  2 | yuan
  3 | jenny
(3 rows)

postgres=# \q
[gpadmin6@gp1 ~]$

复盘分享

  • 6.0安装明显比之前安装起来更舒服更方便了,熟练工基本1分钟就能完成单机测试环境安装;
  • 安装之前会检测一些依赖软件,不至于在安装过程中报错重新去查漏补缺;
  • 数据目录还是需要自己处理,要是数据目录也能自动创建就好了(目前机制可能更注重数据的保护,方式误操作磁盘导致机器上其他数据异常丢失?)
  • 目前Greenplum 6.0版本已经merge到PostgreSQL 9.4了。


关注微信公众号

VMware 中国研发中心