1.下载centos7.9镜像
下载阿里云的centos7.9镜像的地址:centos安装包下载_开源镜像站-阿里云
进入isos目录,下载最小系统版本或者完全版镜像:
然后进入Vmware,开始安装镜像虚拟机;
2.安装虚拟机
新建虚拟机:
移除声卡、usb控制器、打印机;
点击完成;
开启此虚拟机;
按enter键;
等待..
等待checking到达100.0%;
点击开始安装;
设置root的密码,设置自定义用户的用户名和密码,便于记忆,用123456;
等待安装完成;
主页编辑虚拟机设置:
指定使用的iso影像文件为下载的iso文件。
选择桥接网络。
这里已经安装好了,进行重启。
ping www.baidu.com
可以ping通,没有问题,接下来进行静态ip配置,以便后面克隆安装集群。
重新打开虚拟机;
执行命令ifconfig,发现抱错,提示未发现命令,搜索下是否有ifconfig:
search /sbin/ifconfig
提示没有,接下来用yum安装ifconfig;
yum search ifonfig
提示没有可用的ifconfig包
匹配的是net-tools.x86_64,执行命令安装:
yum install net-tools.x86_64 -y
这时候,使用ifconfig,能够执行成功了。
执行yum install vim 安装vim命令,点击Y;
安装成功;
3. 安装docker
检查内核版本:uname -r
[root@localhost ~]# uname -r
3.10.0-1160.el7.x86_64
内核版本3.0以上可以;
执行命令 cat /etc/sysctl.conf ,发现没有内容,加入一行内容:net.ipv4.ip_forward = 1
[root@localhost ~]# echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf &
执行 sysctl -p 显示有 net.ipv4.ip_forward = 1
[root@localhost ~]# sysctl -p
net.ipv4.ip_forward = 1
执行 sudo sysctl -a |grep forward 显示内容中含有一行:net.ipv4.ip_forward = 1
[root@localhost ~]# sudo sysctl -a |grep forward
net.ipv4.conf.all.forwarding = 1
net.ipv4.conf.all.mc_forwarding = 0
net.ipv4.conf.default.forwarding = 1
net.ipv4.conf.default.mc_forwarding = 0
net.ipv4.conf.ens32.forwarding = 1
net.ipv4.conf.ens32.mc_forwarding = 0
net.ipv4.conf.lo.forwarding = 1
net.ipv4.conf.lo.mc_forwarding = 0
net.ipv4.ip_forward = 1
net.ipv4.ip_forward_use_pmtu = 0
sysctl: reading key "net.ipv6.conf.all.stable_secret"
net.ipv6.conf.all.forwarding = 0
net.ipv6.conf.all.mc_forwarding = 0
sysctl: reading key "net.ipv6.conf.default.stable_secret"
net.ipv6.conf.default.forwarding = 0
net.ipv6.conf.default.mc_forwarding = 0
sysctl: reading key "net.ipv6.conf.ens32.stable_secret"
net.ipv6.conf.ens32.forwarding = 0
net.ipv6.conf.ens32.mc_forwarding = 0
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
net.ipv6.conf.lo.forwarding = 0
net.ipv6.conf.lo.mc_forwarding = 0
执行 swapoff -a 关闭swap缓存分区;
执行 rpm -qa|grep yum 检查有没有按照yum的要按照rpm,已经安装跳过;
执行命令 yum install -y yum-utils 安装yum-utils安装程序:
安装后yum-utils检查下:
[root@localhost ~]# rpm -qa|grep yum
yum-3.4.3-168.el7.centos.noarch
yum-utils-1.1.31-54.el7_8.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch
执行 cat /etc/resolv.conf
需要修改resolv.conf
vim /etc/resolv.conf
内容修改含有一行:nameserver 114.114.114.114
执行 yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 添加docker镜像程序;没有报错则继续,如果发现执行报错,解决办法:
ll /etc/yum.repos.d/
执行 yum-config-manager --add-repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
下载CentOS7-Base-163.repo到/etc/yum.repos.d目录下;再执行 yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 下载docker-ce.repo到/etc/yum.repos.d目录下。
执行 yum makecache fast 更新yum源;
执行yum install -y docker-ce docker-ce-cli containerd.io 安装docker服务;
docker安装完成;
执行 docker version 检查docker版本:
添加阿里镜像加速器:
[root@localhost /]# sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors":["https://n0dwemtq.mirror.aliyuncs.com"]
}
EOF
[root@localhost /]# sudo systemctl daemon-reload
[root@localhost /]# sudo systemctl restart docker
执行 sudo systemctl daemon-reload 重新加载服务;
执行 sudo systemctl restart docker 重启docker;
创建并进入目录:
mkdir -p /soft/pack
cd /soft/pack
检查安装的docker的版本:
[root@localhost pack]# docker version
##下载rpm包:
##[root@localhost pack]# wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-23.0.5-1.el7.x86_64.rpm
##如果提示未安装wget命令,则安装wget命令:[root@localhost pack]# yum install -y wget
##如果提示未安装ssl命令,则安装命令:[root@localhost pack]# yum install -y openss*
##安装docker-ce引擎:[root@localhost pack]# yum -y install ./docker-ce-23.0.5-1.el7.x86_64.rpm
开启docker:[root@localhost pack]# sudo systemctl start docker
试运行hello word:[root@localhost pack]# sudo docker run hello-world
检查docker镜像:[root@localhost pack]# docker images
docker删除所有容器: docker rm $(docker ps -aq) 1
docker删除容器:docker rm [container_id]
docker停止容器:docker stop [container_id]
docker 进去容器:docker exec -it [container_id] /bin/bash
docker杀死容器:docker stop [container_id]
docker stop 和docker kill 命令的区别:
docker stop:当我们用docker stop命令来停掉容器的时候,docker默认会允许容器中的应用程序有10秒的时间用以终止运行,在docker stop命令执行的时候,会先向容器中PID为1的进程发送系统信号SIGTERM,然后等待容器中的应用程序终止执行,如果等待时间达到设定的超时时间,或者默认的10秒,会继续发送SIGKILL的系统信号强行kill掉进程。
docker kill:默认情况下,docker kill命令不会给容器中的应用程序有任何等待的机会。它会直接发出SIGKILL的系统信号,以强行终止容器中程序的运行。
docker ps -a 查看所有容器;
4. docker安装单节点greenplum
用docker命令拉取centos7镜像:[root@localhost pack]# docker pull centos:7
检查是否成功拉取:[root@localhost pack]# docker images
运行容器:[root@localhost pack]# sudo docker run -d --name mdw --privileged=true eeb6ee3f44bd /usr/sbin/init
[root@localhost pack]# sudo docker run -d --name sdw1 --privileged=true eeb6ee3f44bd /usr/sbin/init
[root@localhost pack]# sudo docker run -d --name sdw2 --privileged=true eeb6ee3f44bd /usr/sbin/init
[root@localhost pack]# sudo docker run -d --name sdw3 --privileged=true eeb6ee3f44bd /usr/sbin/init
查看所有镜像容器:[root@localhost pack]# docker ps -a
[root@localhost pack]# docker start fbe5cdf4b21a
[root@localhost pack]# docker start 3ed57db09327
[root@localhost pack]# docker start 44d3af1b2279
[root@localhost pack]# docker start 2cfd5202c58b
[root@localhost pack]# docker ps
[root@localhost pack]# docker exec -it fbe5cdf4b21a /bin/bash
删除容器:[root@localhost pack]# docker rm 2cfd5202c58b
删除镜像:[root@localhost pack]# docker rm [image_id或者首字母合适的位数]
docker ps -a 查看所有镜像下的容器并逐个docker rm [container_id] 删除所有容器;
创建外部端口和容器内部端口ssh的映射关系(6002映射22,5432映射5432,6002映射22,5432映射5432):[root@localhost pack]# docker run -itd --name gp-docker01 -p 6002:22 -p 5432:5432 -p 6000:6000 -p 6001:6001 --privileged eeb6ee3f44bd /usr/sbin/init b0c0fe56c04889c3d22aed9f422e16647030517b97f787095b70a8bf84f757a4
6d610c8a70a3f16b54d121da629dfbcc71a83edd00978ab787bf2c663932e4f9
[root@localhost pack]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6d610c8a70a3 eeb6ee3f44bd "/usr/sbin/init b0c0…" 4 minutes ago Up 4 minutes 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp, 0.0.0.0:6000-6001->6000-6001/tcp, :::6000-6001->6000-6001/tcp, 0.0.0.0:6002->22/tcp, :::6002->22/tcp gp-docker01
进入容器:[root@localhost pack]# docker exec -it 6d610c8a70a3 /bin/bash
安装ssh服务 和网络必须应用(否则报错:“bash: ssh-copy-id: command not found”):
[root@6d610c8a70a3 /]# yum -y install openssh*
设置sshd配置文件,打开22端口:
[root@6d610c8a70a3 /]# vi /etc/ssh/sshd_config
将#Port 22这行取消注释,重启sshd服务:
systemctl restart sshd.service
ssh-keygen 创建密钥,一路回车:
执行拷贝密钥的命令ssh-copy-id显示命令未发现,需要安装密钥客户端:
[root@b0c0fe56c048 /]# ssh-copy-id 192.168.2.188(本机ip)
安装passwd应用:[root@6d610c8a70a3 /]# yum -y install passwd
重新设置root密码:[root@b0c0fe56c048 /]# passwd root
设置容器ssh本机免密登录:[root@6d610c8a70a3 /]# ssh-copy-id localhost
exit(ctrl+D)退出容器:
安装rzsz命令方便上传包:
[root@localhost soft]# yum -y install lrzsz
手动下载https://github.com/greenplum-db/gpdb/releases/tag/6.24.3适用于centos7的gp包:
rz上传到/soft目录下;
复制rpm包到容器中:
[root@localhost soft]# docker cp /soft/open-source-greenplum-db-6.24.3-rhel7-x86_64.rpm 6d610c8a70a3:/
进入容器:[root@localhost soft]# docker exec -it 6d610c8a70a3 /bin/bash
创建用户和用户组:
[root@6d610c8a70a3 /]# groupadd gpadmin
[root@6d610c8a70a3 /]# useradd gpadmin -g gpadmin
[root@6d610c8a70a3 /]# passwd gpadmin
检查本机的greenplum的安装包:
[root@6d610c8a70a3 /]# ls |grep greenplum
open-source-greenplum-db-6.24.3-rhel7-x86_64.rpm
安装rpm包到本机localhost:
[root@6d610c8a70a3 /]# yum -y install localhost open-source-greenplum-db-6.24.3-rhel7-x86_64.rpm
安装完毕!检查安装路径:ll /usr/local/ | grep greenplum
将greenplum的目录权限授予给gpadmin用户:
[root@6d610c8a70a3 /]# chown -Rf gpadmin:gpadmin /usr/local/greenplum*
创建gp数据目录并配置数据目录:
[root@6d610c8a70a3 /]# mkdir -p /data/gpdata/master
[root@6d610c8a70a3 /]# mkdir -p /data/gpdata/primary
[root@6d610c8a70a3 /]# mkdir -p /data/gpconfigs
[root@6d610c8a70a3 /]# chown -Rf gpadmin:gpadmin /data/
追加一行内容’source /usr/local/greenplum-db/greenplum_path.sh‘到~/.bashrc文件中,这样在root用户下修改了环境后,一旦切换到gpadmin用户,会自动加载:[gpadmin@6d610c8a70a3 /]$ echo 'source /usr/local/greenplum-db/greenplum_path.sh' >>~/.bashrc
[gpadmin@6d610c8a70a3 /]$ 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一下:
[gpadmin@6d610c8a70a3 /]$ source ~/.bashrc
ssh互信设置:
[gpadmin@6d610c8a70a3 /]$ gpssh-exkeys -h 6d610c8a70a3
拷贝gp初始化系统文件到目录:
[gpadmin@6d610c8a70a3 /]$ cp /usr/local/greenplum-db/docs/cli_help/gpconfigs/gpinitsystem_config /data/gpconfigs/
[gpadmin@6d610c8a70a3 /]$ ls /data/gpconfigs/
gpinitsystem_config
创建host文件:
[gpadmin@6d610c8a70a3 /]$ touch /data/gpconfigs/hostfile
[gpadmin@6d610c8a70a3 /]$ echo "6d610c8a70a3" > /data/gpconfigs/hostfile
编辑修改配置文件,注意master 和 segment的值:
vi /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=(/data1/primary /data1/primary /data1/primary /data2/primary /data2/primary /data2/primary)
declare -a DATA_DIRECTORY=(/data/gpdata/primary /data/gpdata/primary)
#### OS-configured hostname or IP address of the master host.
MASTER_HOSTNAME=6d610c8a70a3
#### 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
################################################
#### OPTIONAL MIRROR PARAMETERS
################################################
#### Base number by which mirror segment port numbers
#### are calculated.
#MIRROR_PORT_BASE=7000
#### 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=(/data1/mirror /data1/mirror /data1/mirror /data2/mirror /data2/mirror /data2/mirror)
################################################
#### OTHER OPTIONAL PARAMETERS
################################################
#### Create a database of this name after initialization.
#DATABASE_NAME=name_of_database
#### Specify the location of the host address file here instead of
#### with the -h option of gpinitsystem.
#MACHINE_LIST_FILE=/home/gpadmin/gpconfigs/hostfile_gpinitsystem
加入内容:
[root@dd15e63680f7 /]# echo "RemoveIPC=no" >> /etc/systemd/logind.conf
/bin/systemctl restart systemd-logind.service
初始化gp数据库:
[gpadmin@6d610c8a70a3 /]$ gpinitsystem -c /data/gpconfigs/gpinitsystem_config -h /data/gpconfigs/hostfile
y确认;
连接数据库:
psql -p 5432 -d postgres
ctrl+Z退出pg终端;
修改gpadmin用户密码:
postgres=# \password gpadmin
Enter new password:
Enter it again:
postgres=#
一路回车,设置好新密码;
开放端口供外部访问使用:
[gpadmin@6d610c8a70a3 /]$ ps -ef | grep greenplum
gpadmin 4188 1 0 07:11 ? 00:00:00 /usr/local/greenplum-db-6.24.3/bin/postgres -D /data/gpdata/primary/gpseg0 -p 6000
gpadmin 4189 1 0 07:11 ? 00:00:00 /usr/local/greenplum-db-6.24.3/bin/postgres -D /data/gpdata/primary/gpseg1 -p 6001
gpadmin 4210 0 0 07:11 ? 00:00:00 /usr/local/greenplum-db-6.24.3/bin/postgres -D /data/gpdata/master/gpseg-1 -p 5432 -E
gpadmin 4393 504 0 07:18 pts/1 00:00:00 grep --color=auto greenplum
容器的6000,6001,5432,分别对应服务器的6000,6001,5432端口,主要开放5432端口允许外部访问即可;
修改配置文件 [gpadmin@6d610c8a70a3 /]$ vi /data/gpdata/master/gpseg-1/pg_hba.conf
添加一行:
host all all all trust
允许所有用户所有ip均可访问;
重启greenplum:
[gpadmin@6d610c8a70a3 /]$ gpstop
20230508:07:29:59:004443 gpstop:6d610c8a70a3:gpadmin-[INFO]:-Starting gpstop with args:
20230508:07:29:59:004443 gpstop:6d610c8a70a3:gpadmin-[INFO]:-Gathering information and validating the environment...
20230508:07:29:59:004443 gpstop:6d610c8a70a3:gpadmin-[CRITICAL]:-gpstop failed. (Reason='Environment Variable MASTER_DATA_DIRECTORY not set!') exiting...
重启报错; 提示设置 MASTER_DATA_DIRECTORY ,于是在文件中增加两行内容
MASTER_DATA_DIRECTORY=/data/gpdata/master/gpseg-1
export MASTER_DATA_DIRECTORY:
[gpadmin@6d610c8a70a3 /]$ vi ~/.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
MASTER_DATA_DIRECTORY=/data/gpdata/master/gpseg-1
export MASTER_DATA_DIRECTORY
[gpadmin@6d610c8a70a3 /]$ source ~/.bashrc
执行命令gpstop重启gp;
重启报错,提示错误:
FATAL: the database system is shutting down
只能手动杀进程来停库了:
[gpadmin@6d610c8a70a3 bin]$ ps -ef | grep greenplum
将查询出来的pid都kill掉:
[gpadmin@6d610c8a70a3 bin]$ kill -9 [PID]
[gpadmin@6d610c8a70a3 bin]$ kill $(ps aux || grep greenplum | tr -s ' '| cut -d ' ' -f 2)
再重启gp:
[gpadmin@6d610c8a70a3 bin]$ gpstart
启动成功;
用连接工具连接:
gpstart gpstop重启报错无法解决,进行如下步骤之后,重新初始化:
[gpadmin@38b12c90c4f4 gpdata]$ rm -f /tmp/.s.PGSQL.*.lock
[root@38b12c90c4f4 /]# chown gpadmin:gpadmin -Rf /data/
[gpadmin@38b12c90c4f4 /]$ rm -rf /data/gpdata/master/*
[gpadmin@38b12c90c4f4 /]$ rm -rf /data/gpdata/primary/*
初始化数据库:
[gpadmin@38b12c90c4f4 /]$ gpinitsystem -c /data/gpconfigs/gpinitsystem_config -h /data/gpconfigs/hostfile
虽然能被访问外网,但是虚拟机每次启动之后ip就会变化,所以要设置静态ip地址;
在 ”我的计算机“ - ”mdw“ - ”设置“:
win+r 输入cmd,执行 ipconfig /all 查看本机的ipv4地址和网关、子网掩码:
vim /etc/sysconfig/network-scripts/ifcfg-ens32 编辑文件:
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static" #改为static(修改)
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens32"
UUID="30959da6-6d05-4072-9b03-70606f159f99"
DEVICE="ens32"
ONBOOT="yes"
IPADDR="192.168.2.188" #本机ip地址(新增)
NETMASK="255.255.255.0" #网关(新增)
NDS1="8.8.8.8" #默认写入(新增)
DNS2="8.8.8.8" #默认写入(新增)
GATWAY="192.168.2.1" #网关和本机网关一致(新增)
重启网卡:service restart network 或者 systemctl restart network
执行ping www.baidu.com 发现可以ping通,用xshell可以连接。