1 环境
操作系统:centos7.6 64位
网络环境:可以访问互联网
2 GreenPlum数据库安装与配置
2.1 GreenPlum安装
3.1.1 资源下载
greenplum官方下载地址:https://network.pivotal.io/products/pivotal-gpdb/
本文下载的资源包是:greenplum-db-5.24.0-rhel7-x86_64.rpm,改版本基于postgresql8.3.23开发。
需注册下载
3.1.2 准备
本次示例准备了四台虚拟机,系统centos7.6 64为
主机名称 | IP地址 | 角色 |
---|---|---|
gp-mst | 192.168.31.27 | master |
gp-sgm1 | 192.168.31.28 | segment |
gp-sgm2 | 192.168.31.30 | segment |
gp-sgm3 | 192.168.31.31 | segment |
附:centos7修改主机名
hostnamectl set-hostname gp-mst # 使用这个命令会立即生效且重启也生效
编辑下hosts文件, 给127.0.0.1添加hostname
vim /etc/hosts
检查
cat /etc/hosts
结果
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 gp-mst
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
注意不要改错了,否则再次开机速度会很慢。
使用上面的方法为所有主机设置好主机名。
2.2 系统基本配置(所有节点)
2.2.1 添加所有节点到host
vim /etc/hosts
添加内容
192.168.31.27 gp-mst
192.168.31.28 gp-sgm1
192.168.31.30 gp-sgm2
192.168.31.31 gp-sgm3
2.2.2 禁用SELinux和防火墙
主机系统必须禁用SELinux和防火墙
vim /etc/selinux/config
将permissive
改为disabled
保存退出。
检查防火墙状态
systemctl status firewalld
如果开启就关闭
systemctl stop firewalld.service
禁止开机启动
systemctl disable firewalld.service
2.2.3 内核参数设置
vim /etc/sysctl.conf
设置内容
# Kernel sysctl configuration file for Red Hat Linux
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
#
# Use '/sbin/sysctl -a' to list all possible parameters.
# Controls IP packet forwarding
net.ipv4.ip_forward = 0
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 1
# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1
# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1
# Disable netfilter on bridges
#net.bridge.bridge-nf-call-ip6tables = 0
#net.bridge.bridge-nf-call-iptables = 0
#net.bridge.bridge-nf-call-arptables = 0
# Controls the default maxmimum size of a mesage queue
kernel.msgmnb = 65536
# Controls the maximum size of a message, in bytes
kernel.msgmax = 65536
kernel.msgmni = 2048
kernel.sem = 250 512000 100 2048
# Controls the maximum shared segment size, in bytes
#kernel.shmmax = 68719476736
kernel.shmmax = 500000000
kernel.shmmni = 4096
# Controls the maximum number of shared memory segments, in pages
#kernel.shmall = 4294967296
kernel.shmall = 4000000000
net.ipv4.tcp_tw_recycle=1
net.ipv4.tcp_max_syn_backlog=4096
net.ipv4.ip_local_port_range = 1025 65535
net.core.netdev_max_backlog=10000
vm.overcommit_memory=2
net.ipv4.conf.all.arp_filter = 1
net.core.rmem_max = 2097152
net.core.wmem_max = 2097152
2.2.4 用户限制
vim /etc/security/limits.conf
在文末添加
#greenplum configs
* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072
说明,如果centos或redhat6版本的,该配置会被/etc/security/limits.d/90-nproc.conf覆盖,注意两边都修改.
不一定是网上资料说的“90”开头,本次示例文件名是“20-nproc.conf”
2.2.5 磁盘访问I/O优化策略
vim /boot/grub/menu.lst
添加
#greenplum configs
elevator=deadline
2.2.6 ntp时间同步
所有节点的时间需同步,都要安装ntp
#安装
yum install ntp
#启动
systemctl start ntpd
#设置开机启动
systemctl enable ntpd
配置:
所有的节点时间与master保持同步。master的时间如果需与某台主机保持同步则配置,否则无需配置。
- master主机上的配置
假如192.168.1.1是数据中心NTP服务器的IP地址,master需与其保持时间同步,则如下配置。否则,请略过。
vim /etc/ntp.conf
追加
server 192.168.1.1
- standby主机上的配置(如果有。本次示例无standby)
追加
`server master
(请自行根据实际情况修改)
- segment主机上的配置
追加
server master prefer #优先于master时间同步
server standby
(请自行根据实际情况修改)
2.3 Master安装和配置
注意:除非特别说明,3.3的操作都只在master主机上
- 创建用户和用户组(在所有节点执行)
groupadd gpadmin
useradd -g gpadmin gpadmin
passwd gpadmin
#可以先设置一个简单的,以后再改,比如gpadmin
- 安装GreenPlum
rpm -ivh greenplum-db-5.24.0-rhel7-x86_64.rpm
如果依赖不满足会列出需要安装的依赖列表,如图
安装缺少的依赖,执行如下命令(根据情况修改)
yum install apr apr-util krb5-devel libevent libyaml rsync zip net-tools
安装依赖完成后再次执行安装命令。
- 改变安装目录的用户和用户组
chown -R gpadmin.gpadmin /usr/local/greenplum-db-5.24.0
- 存储目录创建
切换到gpadmin账户下,在家目录下建立master和segment的数据存放目录。你也可以自行设定数据存放目录,如果你不是以gpadmin建立的目录,还需要修改目录的用户和用户组,最好是建在家目录下。
su - gpadmin
mkdir -p /home/gpadmin/masterdata
mkdir -p /home/gpadmin/segmentdata
mkdir -p /home/gpadmin/segmentmirror
- 创建包含所有主机的文件all_hosts
vim /home/gpadmin/all_hosts
加入所有节点的主机名
本示例添加如下内容
gp-mst
gp-sgm1
gp-sgm2
gp-sgm3
- 创建包含segment主机名的文件
vim /home/gpadmin/seg_hosts
加入所有segment节点主机名
本示例添加如下内容
gp-sgm1
gp-sgm2
gp-sgm3
- 设置gpadmin用户环境
将MASTER_DATA_DIRECTORY加入Master主机环境中,修改gpadmin用户的.bashrc。官方文档里,这一步是放在后面的,因为这里的MASTER_DATA_DIRECTORY路径是根据你设定的master存储数据的路径变动的,这里我把他提前了。如果你是按我的来的,就没问题。如果是自己设定的,就修改一下这个路径,否则后面启动数据库的时候会提示找不到MASTER_DATA_DIRECTORY路径。
修改.bashrc
vim /home/gpadmin/.bashrc
追加
export MASTER_DATA_DIRECTORY=/home/gpadmin/masterdata/gpseg-1
source /usr/local/greenplum-db-6.2.1/greenplum_path.sh
#PS:使用rpm安装的方式默认安装在/usr/local/下,如果你的安装路径与本示例不同,请自行修改
修改.bash_profile
vim /home/gpadmin/.bash_profile
追加
export MASTER_DATA_DIRECTORY=/home/gpadmin/masterdata/gpseg-1
source /usr/local/greenplum-db-6.2.1/greenplum_path.sh
#PS:使用rpm安装的方式默认安装在/usr/local/下,如果你的安装路径与本示例不同,请自行修改
使配置生效
source ~/.bashrc
source ~/.bash_profile
- 建立节点间的信任,配置ssh免密连接
分别切换为gpadmin用户和root用户执行两个用户的n-n免密
在master节点上生成ssh key文件
ssh-keygen
所有会话全部回车即可
使用ssh-copy-id命令将master的public key添加到其他主机上
ssh-copy-id gp-sgm1
ssh-copy-id gp-sgm2
ssh-copy-id gp-sgm3
按照提示语输入密码对应主机上gpadmin用户的密码即可
至此,完成1-n的ssh免密登陆
执行gpssh-exkeys命令完成n-n的ssh免密登录
gpssh-exkeys -f /home/gpadmin/all_hosts
提示成功完成。完成n-n免密登录。(注意!经实测,root用户执行该命令也是输入gpadmin用户的密码,而不是root用户的密码)
2.4 在Segment节点安装
必须切换为root用户执行以下操作。
source /usr/local/greenplum-db-5.24.0/greenplum_path.sh
为所有节点安装
gpseginstall -f /home/gpadmin/all_hosts -u gpadmin -p gpadmin
成功完成Segment的安装!
2.5 初始化
- 创建Greenplum数据库初始化配置文件(在master主机上执行)
在用户目录下创建初始化文件,可以从安装目录下copy模板修改,也可以自己新建添加。如果对配置不是很了解,并且也没有一些特殊配置,建议新建一个文件添加本次示例内容即可。初始化配置文件可以在“你的安装目录/docs/cli_help/gpconfigs/gpinitsystem_config”找到。
本次示例采用第二种方式,因为对配置项也不是很了解。配置直接copy网上资料的一般配置并修改。
vim /home/gpadmin/gpinitsystem_config
添加以下内容。declare的路径根据你所有机器的节点数目来,有几个segment节点,就有几个路径。至于几个PORT的数值,你可以做适当修改,应该只要不大于65535就行,也不要太小,以免和其他软件冲突。
ARRAY_NAME="EMC Greenplum DW"
SEG_PREFIX=gpseg
PORT_BASE=33000
declare -a DATA_DIRECTORY=(/home/gpadmin/segmentdata /home/gpadmin/segmentdata /home/gpadmin/segmentdata)
#注意这里修改主机名
MASTER_HOSTNAME=gp-mst
MASTER_DIRECTORY=/home/gpadmin/masterdata
#GP也是默认5432。因为之前安装了PostgreSQL占用了5432,所以将5432改为5532
MASTER_PORT=5532
MACHINE_LIST_FILE=/home/gpadmin/seg_hosts
TRUSTED_SHELL=ssh
CHECK_POINT_SEGMENTS=8
ENCODING=UNICODE
#以下配置项在有MIRROR节点的时候配置,此示例无
#MIRROR_PORT_BASE=43000
#REPLICATION_PORT_BASE=34000
#MIRROR_REPLICATION_PORT_BASE=44000
#declare -a MIRROR_DATA_DIRECTORY=(/home/gpadmin/segmentmirror /home/gpadmin/segmentmirror)
保存退出
- 为所有节点创建数据储存目录
gp-mst切换到gpadmin用户执行
gpssh -f /home/gpadmin/seg_hosts -e 'mkdir -p /home/gpadmin/segmentdata'
gpssh -f /home/gpadmin/seg_hosts -e 'mkdir -p /home/gpadmin/segmentmirror'
- 执行初始化命令
gpinitsystem -c /home/gpadmin/gpinitsystem_config -h /home/gpadmin/seg_hosts
中途显示
会话输入y回车继续.
结果最后显示
成功!
在master主机上登录测试一下
psql -d postgres -p 5532
注意,此处设置了端口号5532,因为之前安装了PG,如果不设置就登录PG或者提示错误。
2.6 设置密码
GreenPlum类似PostgreSQL,安装后会自动创建一个用户,名为gpadmin。
su gpadmin
默认密码为空,切换到gpadmin用户。
psql -d postgres -p 5532
修改密码
ALTER USER gpadmin with encrypted password 'xxx';
#注:xxx改为你想设置的密码
退出
\q
2.7 配置允许远程访问
greenplum数据库底层封装的是 postgresql 数据库,与 pg 数据库一样,要想登录数据库,需先配置数据库白名单,即允许登录的数据库相关信息。配置文件在$MASTER_DATA_DIRECTORY下。允许远程访问的修改同postgres.注意只需在master节点上操作。
- 配置postgresql.conf`
cd $MASTER_DATA_DIRECTORY
vim postgresql.conf
#listen_addresses = '*'
去掉#改为listen_addresses = '*'
- 配置pg_hba.conf
vim pg_hba.conf
追加
host all all 0.0.0.0/0 md5
改好以后记得重启数据库,gpstop一下,再gpstart一下。
测试
使用pgadmin4测试连接
成功连接
3 GreenPlum数据库一些说明
-
停止和启动集群
- gpstart启动数据库
$ gpstart --help $ gpstart 直接启动,不提示终端用户输入确认 $ gpstart -a 只启动master 实例,主要在故障处理时使用 $ gpstart -m PGOPTIONS='-c gp_session_role=utility' psql 限制模式,只有超级管理员可以连接 $ gpstart -R
- gpstop停止数据库
$ gpstop --help
正常关闭,需要用户输入y|n确认
$ gpstop
$ gpstop -M smart
直接停止,不需要用户输入y|n确认
$ gpstop -a
三种关闭模式
$ gpstop -M smart
$ gpstop -M fast
$ gpstop -M immediate
只停止master 实例,进入维护模式
$ gpstop -m
重新加载配置文件,不停止数据库
$ gpstop –u
重启所有segment 实例
$ gpstop –r
- 集群状态
gpstate -e #查看mirror的状态
gpstate -f #查看standby master的状态
gpstate -s #查看整个GP群集的状态
gpstate -i #查看GP的版本
gpstate --help #帮助文档,可以查看gpstate更多用法
4 PostGis2.1.5 For GreenPlum5
4.1 PostGIS安装和配置
在官网没有找到适配greenplum5的postgis的rpm包和其他安装的资源包,但是4和6都能找到(很奇怪,如果能找到可以参考网上rpm的安装方式)。现在的方案目前只能通过源码编译的方式。
源码编译的方式参考这篇文章:https://mp.weixin.qq.com/s/uU-D6vdv6Nsi3xP1QRpRww
源码github:https://github.com/greenplum-db/geospatial
这篇文章出自pivotal研发中心,算是官方资料吧。
- 下载源码
git clone https://github.com/greenplum-db/geospatial
- 安装依赖
安装依赖方法不赘述。本次示例没有使用上图的版本。
root用户执行
source /usr/local/greenplum-db-5.24.0/greenplum_path.sh
再执行
./configure --prefix=$GPHOME --with-pgconfig=$GPHOME/bin/pg_config --with-raster --without-topology --with-gdalconfig=/usr/local/gdal-2.3.0/bin/gdal-config --with-geosconfig=/usr/local/geos-3.8.0/bin/geos-config --with-projdir=/usr/local/proj-5.2.0 --with-xml2config=/usr/local/libxml2-2.9.10/bin/xml2-config --with-jsondir=/usr/local/json-c-0.12
然后执行编译和安装
make USE_PGXS=1 clean all install
最后
$GPHOME/greenplum_path.sh
下追加以下配置
export GDAL_DATA=$GPHOME/share/gdal
export POSTGIS_ENABLE_OUTDB_RASTERS=0
export POSTGIS_GDAL_ENABLED_DRIVERS=DISABLE_ALL
在所有集群节点上执行同样的安装与配置。
更改配置后重启集群。
4.2 为数据库添加PostGIS扩展
psql -p 5532 -d mydatabase -f ${GPHOME}/share/postgresql/contrib/postgis-2.1/postgis.sql
psql -p 5532 -d mydatabase -f ${GPHOME}/share/postgresql/contrib/postgis-2.1/postgis_comments.sql
psql -p 5532 -d mydatabase -f ${GPHOME}/share/postgresql/contrib/postgis-2.1/rtpostgis.sql
psql -p 5532 -d mydatabase -f ${GPHOME}/share/postgresql/contrib/postgis-2.1/raster_comments.sql