一、配置数据库存储目录
创建一个子节点主机列表文件,包含除去master节点和standby节点的其他节点的主机列表,放置在/opt/greenplum目录下,编辑文件seg_hosts,添加如下内容:
kylin-203-117
kylin-203-122
在每台服务器上创建对应的数据库存储目录,由于一台服务器上配置四台数据库,两台为primary,两台为mirror
[gpadmin@kylin-203-140 greenplum]$ gpssh -f /opt/greenplum/seg_hosts
=> cd /data/greenplum
[kylin-203-122]
[kylin-203-117]
=> mkdir mirror1 mirror2 primary1 primary2
[kylin-203-122]
[kylin-203-117]
=> ll
[kylin-203-122] total 16
[kylin-203-122] drwxrwxr-x. 2 gpadmin gpadmin 4096 Dec 20 15:53 mirror1
[kylin-203-122] drwxrwxr-x. 2 gpadmin gpadmin 4096 Dec 20 15:53 mirror2
[kylin-203-122] drwxrwxr-x. 2 gpadmin gpadmin 4096 Dec 20 15:53 primary1
[kylin-203-122] drwxrwxr-x. 2 gpadmin gpadmin 4096 Dec 20 15:53 primary2
[kylin-203-117] total 16
[kylin-203-117] drwxrwxr-x. 2 gpadmin gpadmin 4096 Dec 20 15:53 mirror1
[kylin-203-117] drwxrwxr-x. 2 gpadmin gpadmin 4096 Dec 20 15:53 mirror2
[kylin-203-117] drwxrwxr-x. 2 gpadmin gpadmin 4096 Dec 20 15:53 primary1
[kylin-203-117] drwxrwxr-x. 2 gpadmin gpadmin 4096 Dec 20 15:53 primary2
=> exit
二、配置gp数据库
配置文件模板都在 /opt/greenplum/greenplum-db/docs/cli_help/gpconfigs,gpinitsystem_config 是初始化Greenplum的模板,此模板中 Mirror Segment的配置都被注释
cp /opt/greenplum/greenplum-db/docs/cli_help/gpconfigs/gpinitsystem_config /opt/greenplum/gpinitsystem_config
gp初始化采用Spread的模式进行分布式部署,所以如果是两台服务器最多只能部署两个primary,每台一个primary,否则将部署失败。编辑内容如下:
# 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=19900
#### 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=(/data/greenplum/primary1)
#### OS-configured hostname or IP address of the master host.
MASTER_HOSTNAME=kylin-203-140
#### File system location where the master data directory
#### will be created.
MASTER_DIRECTORY=/data/greenplum/master
#### Port number for the master instance.
MASTER_PORT=5432
#### Shell utility used to connect to remote hosts.
TRUSTED_SHELL=ssh
#### Maximum log file segments between automatic WAL checkpoints.
CHECK_POINT_SEGMENTS=8
#### Default server-side character set encoding.
ENCODING=UNICODE
################################################
#### OPTIONAL MIRROR PARAMETERS
################################################
#### Base number by which mirror segment port numbers
#### are calculated.
MIRROR_PORT_BASE=19910
#### Base number by which primary file replication port
#### numbers are calculated.
REPLICATION_PORT_BASE=19950
#### Base number by which mirror file replication port
#### numbers are calculated.
MIRROR_REPLICATION_PORT_BASE=19960
#### File system location(s) where mirror segment data directories
#### will be created. The number of mirror locations must equal the
#### number of primary locations as specified in the
#### DATA_DIRECTORY parameter.
declare -a MIRROR_DATA_DIRECTORY=(/data/greenplum/mirror1)
################################################
#### OTHER OPTIONAL PARAMETERS
################################################
#### Create a database of this name after initialization.
DATABASE_NAME=dcw
#### Specify the location of the host address file here instead of
#### with the the -h option of gpinitsystem.
MACHINE_LIST_FILE=/opt/greenplum/seg_hosts
三、配置环境变量
在master节点上编辑.bash_profile配置文件中添加gp相关的环境变量,通过添加PGPORT和PGDATABASE这样在登入gp的时候使用psql可以直接登入dcw数据库。
source /opt/greenplum/greenplum-db/greenplum_path.sh
export MASTER_DATA_DIRECTORY=/data/greenplum/master/gpseg-1
#指定GP安装的数据库的端口号
export PGPORT=5432
#指定默认登入的数据
export PGDATABASE=dcw
保存退出,执行如下指令,使其生效:
source ~/.bash_profile
同步相关环境变量到其他服务器上,执行如下指令进行同步:
gpssh -f /opt/greenplum/other_hosts -e -v "cat >> /home/gpadmin/.bash_profile <<EOF
source /opt/greenplum/greenplum-db/greenplum_path.sh
export MASTER_DATA_DIRECTORY=/data/greenplum/master/gpseg-1
export GPPORT=5432
export PGDATABASE=dcw
EOF"
或者采用拷贝的方式进行配置同步:
gpscp -f /opt/greenplum/other_hosts ~/.bash_profile =:~/.bash_profile
四、初始化gp集群
在master节点和standby节点上创建master目录,否则在创建过程中将不成功:
mkdir -p /opt/greenplum/master
初始化pg,-s 表示standby master,若gp版本为3.8.0不要在初始化加standby master。备份方案有2种(Grouped Miior、Spread Mirror),-S 表示使用Spread Mirror 分配 mirror节点,防止一个节点挂掉,另外一个节点集中成为瓶颈!
gpinitsystem -c /opt/greenplum/gpinitsystem_config -s kylin-203-130 -S
五、初始化失败
若初始化失败,需要删除数据目录重新来。
删除数据存放目录:
gpssh -f /opt/greenplum/hostlist -e -v "cd /data/greenplum/ && rm -rf master/ && rm -rf primary1/ && rm -rf mirror1/ "
删除gpAmdinLogs目录
gpssh -f /opt/greenplum/hostlist -e -v "cd /home/gpadmin/ && rm -rf gpAdminLogs/"
重新创建目录:
gpssh -f /home/gpadmin/conf/hostlist -e -v "mkdir -p /data/greenplum/{master,primary1 ,mirror1 }"
初始化gp集群:
gpinitsystem -c /opt/greenplum/gpinitsystem_config -s kylin-203-130 -S
六、检验安装结果
查看相关进程运行的状态和信息:
ps -aux | grep 5432
ps -aux | grep postgres
七、测试psql
使用psql命令登入gp
#psql -h <hostname or ip> -p <端口> -d [数据库名称] -U [用户名称] -W,在master节点上登入可以不需要输入密码,因为为trust模式,可以省去-W。
psql -h kylin-203-140 -p 5432 -d dcw -U gpadmin -W