绑定完请刷新页面
取消
刷新

分享好友

×
取消 复制
greenplum集群搭建及部署
2023-03-29 11:02:54

一、环境准备
1、准备三台服务器
192.168.123.103 master

192.168.123.104 data1

192.168.123.105 data2

2、更改服务器hosts
#vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.123.103 master
192.168.123.104 data1
192.168.123.105 data2
利用scp直接复制到其他的data节点:

#scp /etc/hosts data1:/etc
#scp /etc/hosts data2:/etc
3、更改服务器之间访问不适用密码
在每台服务器上都需要执行

#ssh-keygen -t rsa #使用root用户运行,四个回车OK
#ssh-copy-id data1 #会提示输入密码,ip1是需要ssh免密码登录的机器IP
#ssh data1 #验证是否成功
4、每台服务器添加分组及用户信息
#groupadd -g 530 gpadmin
#useradd -g 530 -u 530 -m -d /home/gpadmin -s /bin/bash gpadmin
#chown -R gpadmin.gpadmin /home/gpadmin
#echo "mypassword" | passwd --stdin gpadmin
5、修改系统内核
#vim /etc/sysctl.conf

kernel.shmmax=34359738368
kernel.shmall=8388608
kernel.shmmni = 4096
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.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 = 10000 65535
net.core.netdev_max_backlog = 10000
net.core.rmem_max = 2097152
net.core.wmem_max = 2097152
vm.overcommit_memory = 2
vm.overcommit_ratio=95

让配置生效:# sysctl -p(让配置生效)

6、配置进程文件资源限制
#vim /etc/security/limit.conf

* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072
注意:对于RedHat6.x系统,还需要将/etc/security/limits.d/90-nproc.conf文件中 的1024修改为131072。

7、防火墙及SELinux配置管理
防火墙管理:(linux版本不同,查询方式不同)

CentOS 6.5:
关闭防火墙: service iptables stop
关闭开机启动防火墙:chkconfig iptables off
查看防火墙状态: service iptables status


CentOS 7.2:
关闭防火墙: systemctl stop firewalld.service
关闭开机启动防火墙:systemctl disable firewalld.service
查看防火墙状态: systemctl status firewalld.service
开启端口:firewall-cmd --zone=public --add-port=80/tcp --permanent
查看已经开放的端口:firewall-cmd --list-ports
SELinux配置:

#vi /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
二、部署安装Greenplum DB
1、下载安装包
下载地址:https://github.com/greenplum-db/gpdb/releases

2.1、安装编译环境
# yum groupinstall "Development Tools"
# yum install readline
# yum install readline-devel
# yum install zlib-devel
2.2、编译安装Greenplum DB
其中2.1采用编译源码安装,也可以使用rpm包直接安装,如下:

# yum install greenplum-db-6.0.0-rhel7-x86_64.rpm
3、将greenplum的安装路径给gpadmin访问权限
# chown -R gpadmin.gpadmin /usr/local/
# chown -R gpadmin.gpadmin /usr/local/greenplum-db
# chown -R gpadmin.gpadmin /opt/
三、配置Greenplum DB
1.1、创建一个hostlist,包含所有节点主机名
# vi /home/gpadmin/conf/hostlist

master
data1
data2
1.2、创建一个 seg_hosts ,包含所有的Segment Host的主机名
# vim /home/gpadmin/conf/seg_hosts

data1
data2
2、配置ssh免密连接:
[root@ gp-master ~]# su - gpadmin
[gpadmin@ gp-master ~]# source /usr/local/greenplum-db/greenplum_path.sh
[gpadmin@ gp-master ~]# gpssh-exkeys -f /home/gpadmin/conf/hostlist

[STEP 1 of 5] create local ID and authorize on local host
... /home/gpadmin/.ssh/id_rsa file exists ... key generation skipped

[STEP 2 of 5] keyscan all hosts and update known_hosts file

[STEP 3 of 5] authorize current user on remote hosts
... send to gp-sdw1
... send to gp-sdw2
... send to gp-sdw3
#提示:这里提示输入各个子节点gpadmin用户密码
[STEP 4 of 5] determine common authentication file content

[STEP 5 of 5] copy authentication files to all remote hosts
... finished key exchange with gp-sdw1
... finished key exchange with gp-sdw2
... finished key exchange with gp-sdw3

[INFO] completed successfully


测试免密连接是否成功:

[root@ gp-master ~]# ssh data1 #不需要密码即可登录;
或者:

[root@ gp-master ~]# gpssh -f /home/gpadmin/conf/hostlist

=> pwd
[data1] /home/gpadmin
[data2] /home/gpadmin
[master] /home/gpadmin
=> exit
出现上面结果就是成功了。
3、在Segment节点上安装Greenplum DB
在各个子节点进行文件夹赋权:

$ chown -R gpadmin:gpadmin /usr/local
$ chown -R gpadmin:gpadmin /opt

在主节点打包安装包并复制到各个子节点:

$ cd /usr/local/
$ tar -cf gp.tar greenplum-db-5.0.0/
$ gpscp -f /home/gpadmin/conf/seg_hosts gp.tar =:/usr/local/

如果没有意外,就批量复制成功了,可以去子节点的相应文件夹查看,之后要将tar包解压,现在我们将采用对子节点使用批量解压操作:

$ source /usr/local/ greenplum-db/greenplum_path.sh
$ gpssh -f /home/gpadmin/conf/seg_hosts

=> cd /usr/local
[sdw3]
[sdw1]
[sdw2]
=> tar -xf gp.tar
[sdw3]
[sdw1]
[sdw2]

#建立软链接
=> ln -s ./greenplum-db-5.0.0 greenplum-db
[sdw3]
[sdw1]
[sdw2]
=> ll(可以使用ll查看一下是否已经安装成功)
=>exit(退出)

这样就完成了所有节点的安装。



四、初始化数据库
1、创建资源目录

source /usr/local/ greenplum-db/greenplum_path.sh
gpssh -f /home/gpadmin/conf/hostlist #统一处理所有节点

#创建资源目录 /opt/greenplum/data下一系列目录(生产目录个数可根据需求生成)
=> mkdir -p /opt/greenplum/data/master
=> mkdir -p /opt/greenplum/data/primary
=> mkdir -p /opt/greenplum/data/mirror
=> mkdir -p /opt/greenplum/data2/primary
=> mkdir -p /opt/greenplum/data2/mirror
2、环境变量配置
2.1在主节点进行环境变量配置(配置在gpadmin的用户权限下进行配置)
# vi /home/gpadmin/.bash_profile 在后添加

source /usr/local/greenplum-db/greenplum_path.sh
export MASTER_DATA_DIRECTORY=/opt/greenplum/data/master/gpseg-1
export GPPORT=5432
export PGDATABASE=gp_sydb
2.2然后依次复制到各个子节点
# scp /home/gpadmin/.bash_profile gp-sdw1:/home/gpadmin/

2.3 让环境变量生效
# source .bash_profile
3 、NTP 配置

启用master节点上的ntp,并在Segment节点上配置和启用NTP:

echo "server master perfer" >>/etc/ntp.conf
gpssh -f /home/gpadmin/conf/hostlist -v -e 'sudo ntpd'
gpssh -f /home/gpadmin/conf/hostlist -v -e 'sudo /etc/init.d/ntpd start && sudo chkconfig --level 35 ntpd on'
4、初始化前检查连通性

检查节点与节点之间文件读取;

cd /usr/local/greenplum-db/bin
gpcheckperf -f /home/gpadmin/conf/hostlist -r N -d /tmp

-- NETPERF TEST
-------------------

====================
== RESULT
====================
Netperf bisection bandwidth test
master -> gp-sdw1 = 72.220000
data2 -> gp-sdw3 = 21.470000
data1 -> gp-master = 43.510000


Summary:
sum = 181.40 MB/sec
min = 21.47 MB/sec
max = 72.22 MB/sec
avg = 45.35 MB/sec
median = 44.20 MB/sec

出现以上内容证明各个节点已经可以连通。

5、执行初始化

初始化 Greenplum 配置文件模板都在/usr/local/greenplum-db/docs/cli_help/gpconfigs目录下,gpinitsystem_config是初始化 Greenplum 的模板,此模板中 Mirror Segment的配置都被注释;创建一个副本,对其以下配置进行修改:

# cd /usr/local/greenplum-db/docs/cli_help/gpconfigs
# cp gpinitsystem_config initgp_config
# vi initgp_config
#以下为文本要修改的属性字段配置
#资源目录为在前面章节创建的资源目录,配置几次资源目录就是每个子节点有几个实例

declare -a DATA_DIRECTORY=(/opt/greenplum/data/primary /opt/greenplum/data/primary /opt/greenplum/data/primary /opt/greenplum/data2/primary /opt/greenplum/data2/primary /opt/greenplum/data2/primary)
declare -a MIRROR_DATA_DIRECTORY=(/opt/greenplum/data/mirror /opt/greenplum/data/mirror /opt/greenplum/data/mirror /opt/greenplum/data2/mirror /opt/greenplum/data2/mirror /opt/greenplum/data2/mirror)

ARRAY_NAME=”gp_sydb”
MASTER_HOSTNAME=master
MASTER_DIRECTORY=/opt/greenplum/data/master
MASTER_DATA_DIRECTORY=/opt/greenplum/data/master/gpseg-1
DATABASE_NAME=gp_sydb
MACHINE_LIST_FILE=/home/gpadmin/conf/seg_hosts
6、执行初始化;

# gpinitsystem -c initgp_config -S -s standby
若初始化失败,需要删除/opt下的数据资源目录重新初始化;


五、数据库操作

1 停止和启动集群
# gpstop -M fast
# gpstart -a

2 登录数据库
# psql -d postgres #进入某个数据库

postgres=# \l # 查询数据库
List of databases
Name | Owner | Encoding | Access privileges
-----------+---------+----------+---------------------
gp_sydb | gpadmin | UTF8 |
postgres | gpadmin | UTF8 |
template0 | gpadmin | UTF8 | =c/gpadmin
: gpadmin=CTc/gpadmin
template1 | gpadmin | UTF8 | =c/gpadmin
: gpadmin=CTc/gpadmin
(4 rows)
postgres=# \i test.sql #执行sql
postgres=# copy 表名 to '/tmp/1.csv' with 'csv'; #快速导出单表数据
postgres=# copy 表名 from '/tmp/1.csv' with 'csv'; #快速导入单表数据
postgres=# \q #退出数据库

3 集群状态
gpstate -e #查看mirror的状态
gpstate -f #查看standby master的状态
gpstate -s #查看整个GP群集的状态
gpstate -i #查看GP的版本
gpstate --help #帮助文档,可以查看gpstate更多用法

备注:目前为止数据库已经操作完毕,默认只有本地可以连数据库。如果需要别的I可以连,需要修改gp_hba.conf文件

vim $MASTER_DATA_DIRECTORY/pg_hba.conf
#添加
host all gpadmin 0.0.0.0/0 md5
执行gpstop -u使配置生效


本文来源:https://blog.csdn.net/tangsl388/article/details/100554634

分享好友

分享这个小栈给你的朋友们,一起进步吧。

Greenplum
创建时间:2022-04-08 15:36:19
Greenplum
展开
订阅须知

• 所有用户可根据关注领域订阅专区或所有专区

• 付费订阅:虚拟交易,一经交易不退款;若特殊情况,可3日内客服咨询

• 专区发布评论属默认订阅所评论专区(除付费小栈外)

技术专家

查看更多
  • itt0918
    专家
戳我,来吐槽~