Greenplum 主备节点(master和standby)手动切换 步骤详细

1.准备

本次针对GP6.x版本之前
主备节点:
master:node01
standbymaster:node02
 
查看集群备用节点状态:
gpstate -f
20190104:14:34:34:261113 gpstate:node01:gpadmin-[INFO]:-Starting gpstate with args: -f
20190104:14:34:34:261113 gpstate:node01:gpadmin-[INFO]:-local Greenplum Version: 'postgres (Greenplum Database) 5.14.0 build commit:13927a46a9b39527fc1af2cbb1571d4fd394ff88'
20190104:14:34:34:261113 gpstate:node01:gpadmin-[INFO]:-master Greenplum Version: 'PostgreSQL 8.3.23 (Greenplum Database 5.14.0 build commit:13927a46a9b39527fc1af2cbb1571d4fd394ff88) on x86_64-pc-linux-gnu, compiled by GCC gcc (GCC) 6.2.0, 64-bit compiled on Nov 28 2018 08:08:06'
20190104:14:34:34:261113 gpstate:node01:gpadmin-[INFO]:-Obtaining Segment details from master...
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:-Standby master details
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:-----------------------
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:-   Standby address          = node02
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:-   Standby data directory   = /data/master/gpseg-1
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:-   Standby port             = 5432
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:-   Standby PID              = 139960
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:-   Standby status           = Standby host passive
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--------------------------------------------------------------
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--pg_stat_replication
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--------------------------------------------------------------
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--WAL Sender State: streaming
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--Sync state: sync
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--Sent Location: 0/199DF208
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--Flush Location: 0/199DF208
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--Replay Location: 0/199DF208
20190104:14:34:36:261113 gpstate:node01:gpadmin-[INFO]:--------------------------------------------------------------

2.模拟master宕机

在master节点下
# 切换用户
su - gpadmin
# 停止master
pg_ctl stop -s -m fast -D  $MASTER_DATA_DIRECTORY
或者
pg_ctl stop -s -m fast -D /data/master/gpseg-1
返回信息:server stopped
查看standby节点状态(master节点执行)
gpstate -f
20190104:14:56:12:262549 gpstate:node01:gpadmin-[INFO]:-Starting gpstate with args: -f
20190104:14:56:12:262549 gpstate:node01:gpadmin-[INFO]:-local Greenplum Version: 'postgres (Greenplum Database) 5.14.0 build commit:13927a46a9b39527fc1af2cbb1571d4fd394ff88'
20190104:14:56:12:262549 gpstate:node01: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...

集群进入异常状态,无法获取信息

3.激活standby

(1)修改两个文件
su - dbadmin
vi .bashrc
vi .bash_profile
source /usr/local/greenplum-db/greenplum_path.sh
export MASTER_DATA_DIRECTORY=/data/master/gpseg-1
cat >>/home/gpadmin/.bashrc<<-EOF
export PGPORT=5432
EOF
生效:
source ~/.bashrc
 
(2)激活standby节点
gpactivatestandby -d $MASTER_DATA_DIRECTORY
Do you want to continue with standby master activation? Yy|Nn (default=N):
Y 输入Y确认切换
 
再次查看standby节点状态
gpstate -f
20190104:15:05:17:199264 gpstate:node02:gpadmin-[INFO]:-Starting gpstate with args: -f
20190104:15:05:17:199264 gpstate:node02:gpadmin-[INFO]:-local Greenplum Version: 'postgres (Greenplum Database) 5.14.0 build commit:13927a46a9b39527fc1af2cbb1571d4fd394ff88'
20190104:15:05:17:199264 gpstate:node02:gpadmin-[INFO]:-master Greenplum Version: 'PostgreSQL 8.3.23 (Greenplum Database 5.14.0 build commit:13927a46a9b39527fc1af2cbb1571d4fd394ff88) on x86_64-pc-linux-gnu, compiled by GCC gcc (GCC) 6.2.0, 64-bit compiled on Nov 28 2018 08:08:06'
20190104:15:05:17:199264 gpstate:node02:gpadmin-[INFO]:-Obtaining Segment details from master...
20190104:15:05:18:199264 gpstate:node02:gpadmin-[INFO]:-Standby master instance not configured
20190104:15:05:18:199264 gpstate:node02:gpadmin-[INFO]:--------------------------------------------------------------
20190104:15:05:18:199264 gpstate:node02:gpadmin-[INFO]:--pg_stat_replication
20190104:15:05:18:199264 gpstate:node02:gpadmin-[INFO]:--------------------------------------------------------------
20190104:15:05:18:199264 gpstate:node02:gpadmin-[INFO]:-No entries found.
20190104:15:05:18:199264 gpstate:node02:gpadmin-[INFO]:--------------------------------------------------------------

集群可以查看状态,无法获取信息备用节点信息,此时集群可以访问;

将原有主节点添加为standby (master节点,gpadmin账户操作)
这里添加的时候,会check master的数据库目录,要把原master节点的的目录删除或者重命名
mv /data/master/gpseg-1  /data/master/gpseg-1.bak
 
将原有主节点先添加为standby节点(在standby节点)
gpinitstandby -s node01
到此为止主备切换完成

猜你喜欢

转载自blog.csdn.net/qq_35260875/article/details/106221544