本文共 8267 字,大约阅读时间需要 27 分钟。
集群安装信息参考:
系统初始化:集群安装配置:本文对敏感信息进行了替换!!!!
master => gpnode615.kjh.comstandby => gpnode616.kjh.com
命令 参数 作用 gpstate -b =》 显示简要状态gpstate -c =》 显示主镜像映射gpstart -d =》 指定数据目录(默认值:$MASTER_DATA_DIRECTORY)gpstate -e =》 显示具有镜像状态问题的片段gpstate -f =》 显示备用主机详细信息gpstate -i =》 显示GRIPLUM数据库版本gpstate -m =》 显示镜像实例同步状态gpstate -p =》 显示使用端口gpstate -Q =》 快速检查主机状态gpstate -s =》 显示集群详细信息gpstate -v =》 显示详细信息
gpstate -f=>]:-Standby master details=>]:-----------------------=>]:- Standby address = gpnode616.kjh.com=>]:- Standby data directory = /usr/local/gpdata/gpmaster/gpseg-1=>]:- Standby port = 5432=>]:- Standby PID = 45634=>]:- Standby status = Standby host passive=>]:--------------------------------------------------------------=>]:--pg_stat_replication=>]:--------------------------------------------------------------=>]:--WAL Sender State: streaming=>]:--Sync state: sync=>]:--Sent Location: 0/C0006C0=>]:--Flush Location: 0/C0006C0=>]:--Replay Location: 0/C0006C0=>]:--------------------------------------------------------------以上信息显示standby状态正常!
定义:
master => gpnode615.kjh.com (server1) standby => gpnode616.kjh.com (server2)MASTER_DATA_DIRECTORY => /usr/local/gpdata/gpmaster/gpseg-1
pg_ctl stop -D $(MASTER_DATA_DIRECTORY)
or pg_ctl stop -D /usr/local/gpdata/gpmaster/gpseg-1(master节点执行)
$ gpstate -f=> gpadmin-[INFO]:-Starting gpstate with args: -f=> gpadmin-[INFO]:-local Greenplum Version: 'postgres (Greenplum Database) 5.10.2 build => '=> gpadmin-[CRITICAL]:-gpstate failed. (Reason='could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?') exiting...集群进入异常状态,无法获取信息;
(standby节点,gpadmin账户操作)
su - gpadmin cat >>/home/gpadmin/.bashrc<<-EOFsource /usr/local/greenplum-db/greenplum_path.sh export MASTER_DATA_DIRECTORY=/usr/local/gpdata/gpmaster/gpseg-1 export PGPORT=5432EOF
su - gpadmin cat >>/home/gpadmin/.bash_profile<<-EOFsource /usr/local/greenplum-db/greenplum_path.shexport MASTER_DATA_DIRECTORY=/usr/local/gpdata/gpmaster/gpseg-1export PGPORT=5432EOF
source ~/.bashrcsource ~/.bash_profile
(standby节点,gpadmin账户操作)
gpactivatestandby -d /usr/local/gpdata/gpmaster/gpseg-1
=》]:------------------------------------------------------=》]:-Standby data directory = /usr/local/gpdata/gpmaster/gpseg-1=》]:-Standby port = 5432=》]:-Standby running = yes=》]:-Force standby activation = no=》]:------------------------------------------------------
Do you want to continue with standby master activation? Yy|Nn (default=N):> y <== !!!
=》]:-found standby postmaster process。。。。。。。。。。。。。。。。。=》]:-Writing the gp_dbid file - /usr/local/gpdata/gpmaster/gpseg-1/gp_dbid...=》]:-But found an already existing file.=》]:-Hence removed that existing file.=》]:-Creating a new file...=》]:-Wrote dbid: 1 to the file.=》]:-Now marking it as read only...=》]:-Verifying the file...=》]:------------------------------------------------------=》]:-The activation of the standby master has completed successfully.=》]:-cndh1322-6-16 is now the new primary master.=》]:-You will need to update your user access mechanism to reflect=》]:-the change of master hostname.=》]:-operational, this could result in database corruption!=》]:-MASTER_DATA_DIRECTORY is now /usr/local/gpdata/gpmaster/gpseg-1 if=》]:-this has changed as a result of the standby master activation, remember=》]:-to change this in any startup scripts etc, that may be configured=》]:-to set this value.=》]:-MASTER_PORT is now 5432, if this has changed, you=》]:-Do not re-start the failed master while the fail-over master is=》]:-may need to make additional configuration changes to allow access=》]:-to the Greenplum instance.。。。。。。。。。。。。
(standby节点,gpadmin账户操作)
gpstate -f =>]:-Starting gpstate with args: -f=>]:-local Greenplum Version: 'postgres (Greenplum Database) 5.10.2 build =>=>]:-Obtaining Segment details from master...=>]:-Standby master instance not configured=>]:--------------------------------------------------------------=>]:--pg_stat_replication=>]:--------------------------------------------------------------=>]:-No entries found.=>]:--------------------------------------------------------------集群可以查看状态,无法获取信息备用节点信息,此时集群可以访问;
注意这里添加的时候,会check master的数据库目录,要把原master节点的的目录删除或者重命名
mv /usr/local/gpdata/gpmaster/gpseg-1 /usr/local/gpdata/gpmaster/gpseg-1.bak
(standby节点,gpadmin账户操作)
gpinitstandby -s gpnode615.kjh.com =>]:-Validating environment and parameters for standby initialization...=>]:-Checking for filespace directory /usr/local/gpdata/gpmaster/gpseg-1 on gpnode615.kjh.com=>]:------------------------------------------------------=>]:-Greenplum standby master initialization parameters=>]:------------------------------------------------------=>]:-Greenplum master hostname = gpnode616.kjh.com=>]:-Greenplum master data directory = /usr/local/gpdata/gpmaster/gpseg-1=>]:-Greenplum master port = 5432=>]:-Greenplum standby master hostname = gpnode615.kjh.com=>]:-Greenplum standby master port = 5432=>]:-Greenplum standby master data directory = /usr/local/gpdata/gpmaster/gpseg-1=>]:-Greenplum update system catalog = On=>]:------------------------------------------------------=>]:- Filespace locations=>]:------------------------------------------------------=>]:-pg_system -> /usr/local/gpdata/gpmaster/gpseg-1#确认添加从节点Do you want to continue with standby master initialization? Yy|Nn (default=N):> y=>]:-Syncing Greenplum Database extensions to standby=>]:-The packages on gpnode615.kjh.com are consistent.=>]:-Adding standby master to catalog...=>]:-Database catalog updated successfully.=>]:-Updating pg_hba.conf file...=>]:-pg_hba.conf files updated successfully.=>]:-Updating filespace flat files...=>]:-Filespace flat file updated successfully.=>]:-Starting standby master=>]:-Checking if standby master is running on host: gpnode615.kjh.com in directory: /usr/local/gpdata/gpmaster/gpseg-1=>:-Cleaning up pg_hba.conf backup files...=>:-Backup files of pg_hba.conf cleaned up successfully.=>:-Successfully created standby master on gpnode615.kjh.com
gpstate -f=》]:-Obtaining Segment details from master...=》]:-Standby master details=》]:-----------------------=》]:- Standby address = gpnode615.kjh.com=》]:- Standby data directory = /usr/local/gpdata/gpmaster/gpseg-1=》]:- Standby port = 5432=》]:- Standby PID = 29968=》]:- Standby status = Standby host passive=》]:--------------------------------------------------------------=》]:--pg_stat_replication=》]:--------------------------------------------------------------=》]:--WAL Sender State: streaming=》]:--Sync state: sync=》]:--Sent Location: 0/140000A8=》]:--Flush Location: 0/140000A8=》]:--Replay Location: 0/140000A8=》]:--------------------------------------------------------------以上信息显示新添加 gpnode615.kjh.com standby状态正常!
gpnode615.kjh.com
操作方法按照主备切换方法反向操作即可;#### 现集群状态:standby => gpnode615.kjh.com master => gpnode616.kjh.com 以下操作,按照现集群角色配置!!!#### 模拟master节点故障 (gpnode616.kjh.com 节点执行)pg_ctl stop -D /usr/local/gpdata/gpmaster/gpseg-1 #### 激活standby节点 (gpnode615.kjh.com 节点,gpadmin账户操作)gpactivatestandby -d /usr/local/gpdata/gpmaster/gpseg-1 #### 添加standby (gpnode616.kjh.com节点,gpadmin账户操作)注意这里添加的时候,会check master的数据库目录,要把原master节点的的目录删除或者重命名mv /usr/local/gpdata/gpmaster/gpseg-1 /usr/local/gpdata/gpmaster/gpseg-1.bak#### 将原有主节点先添加为standby 节点,(gpnode615.kjh.com节点,gpadmin账户操作)gpinitstandby -s gpnode616.kjh.com #### 验证gpstate -fStandby address = Standby data directory = /usr/local/gpdata/gpmaster/gpseg-1Standby port = 5432Standby PID = 136489Standby status = Standby host passive
转载于:https://blog.51cto.com/michaelkang/2170637