1. 程式人生 > >greenplum(5.10)生產系統主備節點切換

greenplum(5.10)生產系統主備節點切換

node directory usr build refused elk sync 信息 ges

集群安裝信息參考:
系統初始化:http://blog.51cto.com/michaelkang/2167195
集群安裝配置:http://blog.51cto.com/michaelkang/2170627

本文對敏感信息進行了替換!!!!

集群主備節點

master  => gpnode615.kjh.com
standby => gpnode616.kjh.com

狀態查看工具 gpstate

命令     參數   作用 
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

模擬master節點故障 (master節點執行)

pg_ctl stop -D $(MASTER_DATA_DIRECTORY)
or
pg_ctl stop -D /usr/local/gpdata/gpmaster/gpseg-1

再次查看standby節點狀態

(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...

集群進入異常狀態,無法獲取信息;

激活備用節點

設置gpadmin賬戶的環境並使之生效

(standby節點,gpadmin賬戶操作)

修改.bashrc
su - gpadmin 
cat >>/home/gpadmin/.bashrc<<-EOF
source /usr/local/greenplum-db/greenplum_path.sh 
export MASTER_DATA_DIRECTORY=/usr/local/gpdata/gpmaster/gpseg-1 
export PGPORT=5432
EOF
修改.bash_profile
su - gpadmin 
cat >>/home/gpadmin/.bash_profile<<-EOF
source /usr/local/greenplum-db/greenplum_path.sh
export MASTER_DATA_DIRECTORY=/usr/local/gpdata/gpmaster/gpseg-1
export PGPORT=5432
EOF
使之生效
source ~/.bashrc
source ~/.bash_profile

激活standby節點

(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節點狀態

(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.
=>]:--------------------------------------------------------------

集群可以查看狀態,無法獲取信息備用節點信息,此時集群可以訪問;

將原有主節點添加為standby (master節點,gpadmin賬戶操作)

註意這裏添加的時候,會check master的數據庫目錄,要把原master節點的的目錄刪除或者重命名

mv /usr/local/gpdata/gpmaster/gpseg-1 /usr/local/gpdata/gpmaster/gpseg-1.bak

將原有主節點先添加為standby 節點

(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狀態正常!

將master 切換至原節點

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 -f

Standby address          = 
Standby data directory   = /usr/local/gpdata/gpmaster/gpseg-1
Standby port             = 5432
Standby PID              = 136489
Standby status           = Standby host passive

greenplum(5.10)生產系統主備節點切換