??如果有充分的资源,可以做分布式安装GreenPlum。如果资源不足,可以做单节点安装,同样可以用来熟悉GreenPlum语法。本章计划使用Docker创建一个Centos7的镜像,并在Centos7中安装GreenPlum。如果不打算使用Docker的话,可以直接从第二步安装GreenPlum开始。
docker pull centos:7
[root@zxy ~]# docker pull centos:7
[root@zxy ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 eeb6ee3f44bd 18 months ago 204MB
外部端口6002映射容器内部ssh端口22
外部端口5432映射内部端口5432
外部端口6000映射内部端口6000
外部端口6001映射内部端口6001
[root@zxy ~]# docker run -itd --name gp-docker01 \
> -p 6002:22 \
> -p 5432:5432 \
> -p 6000:6000 \
> -p 6001:6001 \
> --privileged eeb6ee3f44bd \
> /usr/sbin/init
b0c0fe56c04889c3d22aed9f422e16647030517b97f787095b70a8bf84f757a4
[root@zxy ~]# docker exec -it b0c0fe56c048 /bin/bash
[root@b0c0fe56c048 /]#
如果在执行ssh-keygen
的时候,找不到该命令,那么使用yum
安装openssh
即可
bash: ssh-keygen: command not found
# 1.ssh-keygen失败
[root@b0c0fe56c048 /]# ssh-keygen
bash: ssh-keygen: command not found
# 2.安装openssh
[root@b0c0fe56c048 /]# yum install openssh
# 3.再次进行生成密钥操作,不用输入,直接点击enter键即可
[root@b0c0fe56c048 /]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
......
如果在执行ssh-copy-id
失败的话,使用yum
手动安装openssh-clients
即可
bash: ssh-copy-id: command not found
# 1.拷贝失败
[root@b0c0fe56c048 /]# ssh-copy-id 125.22.95.188
bash: ssh-copy-id: command not found
# 2.安装openssh-clients
[root@b0c0fe56c048 /]# yum install openssh-clients
# 3.再次拷贝,进行免密
[root@b0c0fe56c048 /]# ssh-copy-id 125.22.95.188
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '125.22.95.188 (125.22.95.188)' can't be established.
ECDSA key fingerprint is SHA256:uvxqg9O/HlNw5Y3FNToE/llF8GeZQy/p+GXlIS3N6cY.
ECDSA key fingerprint is MD5:d4:15:a9:ea:f9:26:8f:2f:b4:dd:8a:42:3b:58:29:3b.
Are you sure you want to continue connecting (yes/no)? yes
.....
[root@b0c0fe56c048 /]# yum -y install net-tools.x86_64
[root@b0c0fe56c048 /]# yum -y install openssh-server
[root@b0c0fe56c048 /]# systemctl restart sshd
安装passwd应用,可以给容器的用户设置密码,方便对本机进行免密操作
[root@b0c0fe56c048 /]# yum -y install passwd
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: ftp.sjtu.edu.cn
* updates: ftp.sjtu.edu.cn
Package passwd-0.79-6.el7.x86_64 already installed and latest version
Nothing to do
[root@b0c0fe56c048 /]# passwd root
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@b0c0fe56c048 /]# ssh-copy-id localhost
...
Are you sure you want to continue connecting (yes/no)? yes
...
root@localhost's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'localhost'"
and check to make sure that only the key(s) you wanted were added.
[root@zxy ~]# docker cp /zxy/software/greenplum-db-6.4.0-rhel6-x86_64.rpm b0c0fe56c048:/
[root@b0c0fe56c048 /]# groupadd gpadmin
[root@b0c0fe56c048 /]# useradd gpadmin -g gpadmin
[root@b0c0fe56c048 /]# passwd gpadmin
??官方推荐使用yum的方式安装,yum安装的饿好处是,会自动帮我们下载安装依赖包。默认将greenplum软件安装到/usr/local目录下,并创建软连接。但是如果不能自动联网下载就会比较麻烦。
[root@b0c0fe56c048 /]# ls | grep greenplum
greenplum-db-6.4.0-rhel6-x86_64.rpm
[root@b0c0fe56c048 /]# yum install localhost greenplum-db-6.4.0-rhel6-x86_64.rpm
[root@b0c0fe56c048 /]# ll /usr/local/ | grep greenplum
lrwxrwxrwx 1 root root 29 Mar 22 02:29 greenplum-db -> /usr/local/greenplum-db-6.4.0
drwxr-xr-x 12 root root 4096 Mar 22 02:29 greenplum-db-6.4.0
[root@b0c0fe56c048 /]# chown -Rf gpadmin:gpadmin /usr/local/greenplum*
[root@b0c0fe56c048 /]# ll /usr/local/ | grep greenplum
lrwxrwxrwx 1 gpadmin gpadmin 29 Mar 22 02:29 greenplum-db -> /usr/local/greenplum-db-6.4.0
drwxr-xr-x 12 gpadmin gpadmin 4096 Mar 22 02:29 greenplum-db-6.4.0
创建数据目录gpdata
有master
和primary
等节点
创建配置目录gpconfigs
[root@b0c0fe56c048 /]# mkdir -p /data/gpdata/master
[root@b0c0fe56c048 /]# mkdir -p /data/gpdata/primary
[root@b0c0fe56c048 /]# mkdir -p /data/gpconfigs
[root@b0c0fe56c048 /]# chown -Rf gpadmin:gpadmin /data/
[root@b0c0fe56c048 /]# su gpadmin
在~/.bashrc文件中添加source /usr/local/greenplum-db/greenplum_path.sh
这样在root用户下修改了环境后,一旦切换到gpadmin用户,会自动加载。
后续还有其他变量需要添加时,也添加在该文件中
[gpadmin@b0c0fe56c048 /]$ 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
刚修改好,可以手动source一下。source ~/.bashrc
[gpadmin@b0c0fe56c048 /]$ gpssh-exkeys -h b0c0fe56c048
[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
cp /usr/local/greenplum-db/docs/cli_help/gpconfigs/gpinitsystem_config /data/gpconfigs/
[gpadmin@b0c0fe56c048 /]$ cp /usr/local/greenplum-db/docs/cli_help/gpconfigs/gpinitsystem_config /data/gpconfigs/
[gpadmin@b0c0fe56c048 /]$ touch /data/gpconfigs/hostfile
[gpadmin@b0c0fe56c048 /]$ echo "b0c0fe56c048" > /data/gpconfigs/hostfile
主要关注master和segment的目录,主机名和数据库端口
[gpadmin@b0c0fe56c048 /]$ vi /data/gpconfigs/gpinitsystem_config
[gpadmin@b0c0fe56c048 /]$ cat /data/gpconfigs/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=(/data/gpdata/primary /data/gpdata/primary)
#### OS-configured hostname or IP address of the master host.
MASTER_HOSTNAME=b0c0fe56c048
#### File system location where the master data directory
#### will be created.
MASTER_DIRECTORY=/data/gpdata/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
gpinitsystem -c /data/gpconfigs/gpinitsystem_config -h /data/gpconfigs/hostfile
[gpadmin@b0c0fe56c048 /]$ gpinitsystem -c /data/gpconfigs/gpinitsystem_config -h /data/gpconfigs/hostfile
[gpadmin@b0c0fe56c048 /]$ psql -p 5432 -d postgres
psql (9.4.24)
Type "help" for help.
[gpadmin@b0c0fe56c048 /]$ psql -p 5432 -d postgres
psql (9.4.24)
Type "help" for help.
postgres=# \password gpadmin
Enter new password:
Enter it again:
通过指令查询任务进程,以及端口。
容器的6000,6001,5432,分别对应服务器的6000,6001,5432端口,主要开放5432端口允许外部访问即可
[gpadmin@b0c0fe56c048 /]$ ps -ef | grep greenplum
gpadmin 3560 1 0 02:39 ? 00:00:00 /usr/local/greenplum-db-6.4.0/bin/postgres -D /data/gpdata/primary/gpseg0 -p 6000
gpadmin 3561 1 0 02:39 ? 00:00:00 /usr/local/greenplum-db-6.4.0/bin/postgres -D /data/gpdata/primary/gpseg1 -p 6001
gpadmin 3582 0 0 02:39 ? 00:00:00 /usr/local/greenplum-db-6.4.0/bin/postgres -D /data/gpdata/master/gpseg-1 -p 5432 -E
gpadmin 3725 405 0 02:43 pts/1 00:00:00 grep --color=auto greenplum
#添加如下一行即可,所有用户,所有IP均可访问
#生产环境中可自行选择配置
[gpadmin@b0c0fe56c048 /]$ vi /data/gpdata/master/gpseg-1/pg_hba.conf
host all all all trust
20230322:02:45:30:003728 gpstop:b0c0fe56c048:gpadmin-[CRITICAL]:-gpstop failed. (Reason='Environment Variable MASTER_DATA_DIRECTORY not set!') exiting...
在使用gpstop的时候,提示关闭失败,提示你设置MASTER_DATA_DIRECTORY
[gpadmin@b0c0fe56c048 /]$ gpstop
20230322:02:45:30:003728 gpstop:b0c0fe56c048:gpadmin-[INFO]:-Starting gpstop with args:
20230322:02:45:30:003728 gpstop:b0c0fe56c048:gpadmin-[INFO]:-Gathering information and validating the environment...
20230322:02:45:30:003728 gpstop:b0c0fe56c048:gpadmin-[CRITICAL]:-gpstop failed. (Reason='Environment Variable MASTER_DATA_DIRECTORY not set!') exiting...
在~/.bashrc
文件中添加如下两行记录即可
[gpadmin@b0c0fe56c048 /]$ vi ~/.bashrc
MASTER_DATA_DIRECTORY=/data/gpdata/master/gpseg-1
export MASTER_DATA_DIRECTORY
[gpadmin@b0c0fe56c048 /]$ source ~/.bashrc
[gpadmin@b0c0fe56c048 /]$ gpstop
.....
20230322:02:46:57:003750 gpstop:b0c0fe56c048:gpadmin-[INFO]:-Cleaning up leftover shared memory
[gpadmin@b0c0fe56c048 /]$ gpstart
......
20230322:02:47:21:003933 gpstart:b0c0fe56c048:gpadmin-[INFO]:-Database successfully started
Dbeaver使用GreenPlum驱动连接数据库