一、环境准备
1、准备10台机器
gp-master
gp-standby
gp-s1
gp-s2
gp-s3
gp-s4
gp-s5
gp-s6
gp-s7
gp-s8
安装centos6.8
2、更改服务器hosts
#vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.66.33 gp-master
192.168.66.34 gp-standby
192.168.66.35 gp-s1
192.168.66.36 gp-s2
192.168.66.37 gp-s3
192.168.66.38 gp-s4
192.168.66.39 gp-s5
192.168.66.40 gp-s6
192.168.66.41 gp-s7
192.168.66.42 gp-s8
3、更改服务器之间访问不适用密码
在每台服务器上都需要执行
#ssh-keygen -t rsa #使用root用户运行,四个回车OK
#ssh-copy-id gp-standby #会提示输入密码,ip1是需要ssh免密码登录的机器IP
#ssh gp-standby #验证是否成功
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 "123456" | 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
#vim /etc/security/limits.d/90-nproc.conf
* soft nproc 131072
* hard nproc 131072
* soft nofile 1048576
* hard nofile 1048576
磁盘预读参数及 deadline算法修改
blockdev --setra 65536 /dev/sda
echo deadline > /sys/block/sda/queue/scheduler
7、防火墙及SELinux配置管理
CentOS 6.8:
关闭防火墙: service iptables stop
关闭开机启动防火墙:chkconfig iptables off
查看防火墙状态: service iptables status
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、下载 greenplum-db-6.7.0-rhel6-x86_64.rpm
安装依赖包
sudo yum install -y apr apr-util bash bzip2 curl krb5 libcurl libevent libxml2 libyaml zlib openldap openssh openssl openssl-libs perl readline rsync R sed tar zip krb5-devel
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
gp-master
gp-standby
gp-s1
gp-s2
gp-s3
gp-s4
gp-s5
gp-s6
gp-s7
gp-s8
1.2创建一个seg_hosts,包含所有的Segment Host的主机名
# vim /home/gpadmin/conf/seg_hosts
gp-s1
gp-s2
gp-s3
gp-s4
gp-s5
gp-s6
gp-s7
gp-s8
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
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
[gp-s1]
[gp-s2]
[gp-s3]
[gp-s4]
[gp-s5]
[gp-s6]
[gp-s7]
[gp-s8]
=> tar -xf gp.tar
[gp-s1]
[gp-s2]
[gp-s3]
[gp-s4]
[gp-s5]
[gp-s6]
[gp-s7]
[gp-s8]
#建立软链接
=> ln -s ./greenplum-db-6.7.0 greenplum-db
[gp-s1]
[gp-s2]
[gp-s3]
[gp-s4]
[gp-s5]
[gp-s6]
[gp-s7]
[gp-s8]
=> 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的用户权限下进行配置)
1). 先切换gpadmin用户
sudo su gpadmin
2).再添加内容到~/.bashrc
cat >> ~/.bashrc << EOF
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
EOF
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
检查节点与节点之间文件读取;
image.png
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=gp-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 gp-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 #退出数据库
image.png
3 集群状态
gpstate -e #查看mirror的状态
gpstate -f #查看standby master的状态
gpstate -s #查看整个GP群集的状态
gpstate -i #查看GP的版本
gpstate --help #帮助文档,可以查看gpstate更多用法
备注:目前为止数据库已经操作完毕,默认只有本地可以连数据库。如果需要别的I可以连,需要修改gp_hba.conf文件
vim /opt/greenplum/data/master/gpseg-1/pg_hba.conf
#添加
host all gpadmin 0.0.0.0/0 md5
执行gpstop -u使配置生效
网友评论