溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Oracle HA雙機主備基于共享存儲模式并利用keepalived管理實現(xiàn)高可用

發(fā)布時間:2020-06-07 08:51:16 來源:網(wǎng)絡(luò) 閱讀:32237 作者:HMLinux 欄目:關(guān)系型數(shù)據(jù)庫

HA概述

 

HA(High Available)即由兩臺計算機組成并對外提供一組相同的服務(wù),也叫做一主一備模式。正常情況下由主服務(wù)器提供服務(wù),備服務(wù)器處于待機備用,備機可以隨時接替主服務(wù)器的工作。也就是當(dāng)主服務(wù)器宕機或所提供的服務(wù)不可用時,備用服務(wù)器會主動激活并且替換主服務(wù)器繼續(xù)提供服務(wù),這時主服務(wù)器上的服務(wù)資源包括網(wǎng)絡(luò)(IP)、存儲、服務(wù)(Web/數(shù)據(jù)庫)就會轉(zhuǎn)移到備機接管,從而提供不間斷的服務(wù)?;诖耍憧梢詫⒎?wù)器的宕機時間減少到最低,對業(yè)務(wù)實現(xiàn)不中斷或短暫中斷。

 

由一組計算機(多臺)組成一個整體并向用戶提供相同的網(wǎng)絡(luò)資源或服務(wù),這種模式叫做HA集群(High Available Cluster)。

 

Oracle HA

Oracle HA高可用,又叫做雙機熱備,一般用于關(guān)鍵性業(yè)務(wù)。

 

Oracle雙機熱備模式

常用的有Data Guard、RAC(Real Application Clusters)、基于HA軟件實現(xiàn)的雙機熱備。

 

作用和區(qū)別

 

l  Data Guard采用重做日志復(fù)制技術(shù),對主業(yè)務(wù)數(shù)據(jù)進(jìn)行實時的異步同步備份,有一主一備、一主多備模式,一般常用于容災(zāi)(異地備份、災(zāi)難恢復(fù));存儲獨立、數(shù)據(jù)完整備份;備機可以做數(shù)據(jù)分析、報表統(tǒng)計等;主備自由切換,能實現(xiàn)自動快速故障轉(zhuǎn)移;備用角色強制轉(zhuǎn)換為主用角色會破環(huán)Data Guard架構(gòu);設(shè)計復(fù)雜、維護(hù)難度大

 

l  RAC多個實例同時運行,無主備概念,有集群負(fù)載功能,其中某一臺down機,不影響整體服務(wù),不存在故障切換時間,可以提供高性能服務(wù);存儲共享,由ASM管理存儲;硬件成本低;設(shè)計簡單、維護(hù)難度大

 

l  HA雙機熱備可以提供高可用性,保證業(yè)務(wù)的持續(xù)穩(wěn)定運行,可以實現(xiàn)自動快速故障轉(zhuǎn)移,存在短暫的切換時間(10-30s)。一般用于關(guān)鍵性業(yè)務(wù);存儲共享;有商業(yè)的HA方案,也可以使用開源的高可用軟件keepalved、heartbeat搭建實現(xiàn)HA方案;設(shè)計復(fù)雜、維護(hù)難度小

 

自由組合

l  HA雙機和Data Guard

l  Data Guard和RAC


Oracle HA+Keepalived架構(gòu)

l  Oracle HA雙機熱備+Keepalived

Oracle HA雙機主備基于共享存儲模式并利用keepalived管理實現(xiàn)高可用



l  Oracle HA雙機+DataGuard+Keepalived集群

Oracle HA雙機主備基于共享存儲模式并利用keepalived管理實現(xiàn)高可用



搭建Oracle HA主備服務(wù)器

軟件版本:

Orace 11g R2

Keepalived 1.3.2

 

主服務(wù)器: DB1

備服務(wù)器: DB2

 

環(huán)境介紹

Hostname

IP

OS

Role

hmdg-db1

172.16.10.25

CentOS6.9

MASTER

hmdg-db2

172.16.10.26

CentOS6.9

BACKUP

VIP

172.16.10.130、172.16.10.131

Share Disk

/dev/sdb1 mount on /oradata

ORACLE_BASE

/u01/app/oracle

ORACLE_HOME

/u01/app/oracle/product/11.2.0/db_1

ORACLE_SID

HMODB

Datadir

/oradata/HMODB

Controlfiles

/oradata/HMODB/control01.ctl, /u01/app/oracle/flash_recovery_area/HMODB/control02.ctl,

/home/oracle/rman/HMODB/control03.ctl

 

Oracle軟件安裝步驟

 

1、 同時在主備上安裝Oracle數(shù)據(jù)庫軟件,數(shù)據(jù)庫的安裝目錄和環(huán)境變量保持一致

2、 僅在主服務(wù)器上建立數(shù)據(jù)庫實例(主服務(wù)器上掛載共享存儲并使用DBCA新建庫)

3、 主服務(wù)創(chuàng)建數(shù)據(jù)庫實例后,將主庫上的控制文件、參數(shù)文件(SPFILE)、以及密碼文件傳輸?shù)絺溆梅?wù)器上相應(yīng)的目錄


l  備用服務(wù)器DB2

##創(chuàng)建對應(yīng)的數(shù)據(jù)庫文件目錄
[root@hmdg-db2 ~]# su - oracle
[oracle@hmdg-db2 ~]$ mkdir /u01/app/oracle/admin/HMODB
[oracle@hmdg-db2 ~]$ mkdir /u01/app/oracle/admin/HMODB/{adump,dpdump,pfile}
[oracle@hmdg-db2 ~]$ mkdir /u01/app/oracle/flash_recovery_area/HMODB
 
##密碼文件
[oracle@hmdg-db2 ~]$ scp oracle@hmdg-db1:/u01/app/oracle/product/11.2.0/db_1/dbs/orapwHMODB /u01/app/oracle/product/11.2.0/db_1/dbs/orapwHMODB
 
##SPFILE參數(shù)文件
[oracle@hmdg-db2 ~]$ scp oracle@hmdg-db1:/u01/app/oracle/product/11.2.0/db_1/dbs/spfileHMODB.ora /u01/app/oracle/product/11.2.0/db_1/dbs/spfileHMODB.ora
 
##控制文件,僅需要將位于非共享存儲的數(shù)據(jù)目錄下的控制文件傳輸?shù)狡渌疟P或目錄位置下
[oracle@hmdg-db2 ~]$ scp oracle@hmdg-db1:/u01/app/oracle/flash_recovery_area/HMODB/control02.ctl /u01/app/oracle/flash_recovery_area/HMODB/control02.ctl
 
[oracle@hmdg-db2 ~]$cp /u01/app/oracle/flash_recovery_area/HMODB/control02.ctl /home/oracle/rman/HMODB/control03.ctl


在備用服務(wù)器上啟動數(shù)據(jù)庫

1、 主服務(wù)器上關(guān)閉數(shù)據(jù)庫實例

2、 主服務(wù)器上卸載共享存儲

3、 備服務(wù)器上掛載共享存儲

4、 備服務(wù)器上啟動監(jiān)聽

5、 備服務(wù)器上啟動數(shù)據(jù)庫實例

 

注意:不要同時掛載共享存儲啟動數(shù)據(jù)庫實例,否則會導(dǎo)致數(shù)據(jù)不一致

 

l  主服務(wù)器DB1

##關(guān)閉數(shù)據(jù)庫實例
[oracle@hmdg-db1 ~]$ sqlplus / as sysdba
SQL> shutdown immediate
 
##關(guān)閉數(shù)據(jù)庫監(jiān)聽
[oracle@hmdg-db1 ~]$ lsnrctl stop
 
##卸載共享存儲
[oracle@hmdg-db1 ~]$ umount /oradata


l  備服務(wù)器DB2

##掛載/dev/sdb1共享存儲到/oradta下
[root@hmdg-db2 ~]# mount /dev/sdb1 /oradata/
 
##啟動數(shù)據(jù)庫監(jiān)聽
[oracle@hmdg-db2 ~]$ lsnrctl start
[oracle@hmdg-db2 ~]$ export ORACLE_SID=HMODB
 
##啟動數(shù)據(jù)庫實例
[oracle@hmdg-db2 ~]$ sqlplus / as sysdba
 
SQL> startup
ORACLE instance started.
 
Total System Global Area 1603411968 bytes
Fixed Size          2213776 bytes
Variable Size        1056966768 bytes
Database Buffers      536870912 bytes
Redo Buffers            7360512 bytes
Database mounted.
Database opened.
SQL>
 
##檢驗數(shù)據(jù)庫
SQL> SHOW PARAMETER DB_NAME
 
NAME                    TYPE    VALUE
------------------------------------ ----------- ------------------------------
db_name                  string  HMODB
 
SQL> SELECT OPEN_MODE,NAME,DATABASE_ROLE FROM V$DATABASE;
 
OPEN_MODE        NAME      DATABASE_ROLE
-------------------- --------- ----------------
READ WRITE       HMODB     PRIMARY


再次手動切換步驟

由于安裝數(shù)據(jù)庫實例時,創(chuàng)建了多個控制文件,并且這些控制文件都保存在不同的磁盤上,在主備進(jìn)行切換的時,位于非共享存儲的控制文件需要手動進(jìn)行同步。這是由于在關(guān)閉數(shù)據(jù)庫實例時Oracle同時將當(dāng)前數(shù)據(jù)庫狀態(tài)信息記錄到控制文件中,在沒有啟動數(shù)據(jù)庫實例的備機就無法同步自身的其他的控制文件。這時就需要使用共享存儲里的控制文件進(jìn)行恢復(fù)。


1、 在DB2關(guān)閉正在運行數(shù)據(jù)庫實例

##DB2:
[oracle@hmdg-db2 ~]$ sqlplus / as sysdba
SQL> shutdown immediate
[root@hmdg-db2 ~]# umount /oradata/

 

2、在DB1上進(jìn)行恢復(fù)啟動數(shù)據(jù)庫實例

##DB1:
[root@hmdg-db1 ~]# mount /dev/sdb1 /oradata/
[oracle@hmdg-db1 ~]$ export ORACLE_SID=HMODB
 
[oracle@hmdg-db1 ~]$ sqlpus / as sysdba
SQL> startup nomount
SQL> alter database mount;
SQL> alter database open;

 

如果控制文件在不同的磁盤目錄,那么就需要執(zhí)行這一步恢復(fù)控制文件

[oracle@hmdg-db1 ~]$ rman target /
RMAN> restore controlfile from '/oradata/HMODB/control01.ctl';

 啟動數(shù)據(jù)庫監(jiān)聽

[oracle@hmdg-db1 ~]$ lsnrctl start

 

或者直接只有操作系統(tǒng)的cp、scp等命令進(jìn)行拷貝恢復(fù)

[oracle@hmdg-db1 ~]$ cp /oradata/HMODB/control01.ctl /u01/app/oracle/flash_recovery_area/HMODB/control02.ctl

SQL> SELECT NAME,OPEN_MODE,NAME,DATABASE_ROLE FROM V$DATABASE;
 
NAME      OPEN_MODE        NAME  DATABASE_ROLE
--------- -------------------- --------- ----------------
HMODB     READ WRITE           HMODB     PRIMARY


主備服務(wù)SSH密鑰配置

配置oracle用戶的ssh密鑰,用于主備通過oracle身份自動檢測對方的數(shù)據(jù)共享存儲狀態(tài)。在keepalived腳本管理中自動檢查對方的掛載狀態(tài),并在主備切換的過程中,待接管的服務(wù)器等待對方umount共享存儲之后,正常啟動數(shù)據(jù)庫實例。(如果主服務(wù)異常關(guān)機或網(wǎng)絡(luò)中斷,不需要等待對方umount存儲,主服務(wù)器異常關(guān)機時keepalived會即時檢測到并自動切換到備機上)

[oracle@hmdg-db1 ~]$ ssh-keygen -t rsa -b 2048
[oracle@hmdg-db1 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub oracle@hmdg-db2
 
[oracle@hmdg-db2 ~]$ ssh-keygen -t rsa -b 2048
[oracle@hmdg-db2 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub oracle@hmdg-db1

 

添加主備防火墻互通規(guī)則

# iptables -I INPUT -p tcp -s 172.16.10.0/24 -j ACCEPT
# iptables -I INPUT -p udp -s 172.16.10.0/24 -j ACCEPT



Keepalived配置和管理腳本

keepalived配置

主服務(wù)器的keepalived配置,備用服務(wù)器需要做相應(yīng)的修改

! Configuration File for keepalived
 
global_defs {
   notification_email {
       mail@huangming.org
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id ORACLE_HA_MASTER    #backup為ORACLE_HA_BACKUP
   !vrrp_skip_check_adv_addr
}
 
vrrp_sync_group ORACLE_HA_GROUP {
    group {
        Oracle_HA_1    #定義一個vrrp實例組
    }
}
 
vrrp_script monitor_oracle_status {    #oracle數(shù)據(jù)庫服務(wù)器狀態(tài)檢查腳本
    script "/usr/local/keepalived/scripts/monitor.sh"
    interval 10    #腳本執(zhí)行時間間隔
    fall 3         #腳本執(zhí)行的最大失敗次數(shù)
    rise 1         #腳本執(zhí)行成功一次則返回正常狀態(tài)
    weight 20      #腳本執(zhí)行成功時的附加權(quán)值
}
 
vrrp_script change_monitor_status {    #服務(wù)器狀態(tài)監(jiān)控并修改主備檢查腳本
    script "/usr/local/keepalived/scripts/change_monitor_status.sh"
    interval 2
}
 
vrrp_instance Oracle_HA_1 {
    state BACKUP            #主備都設(shè)置為BACKUP
    interface eth2          #綁定vip的網(wǎng)絡(luò)接口
    virtual_router_id 200   #主備保存一致
    priority 100            #備為90
    advert_int 2            #主備狀態(tài)同步時間間隔
    nopreempt               #主設(shè)置為不搶占模式
    authentication {
        auth_type PASS
        auth_pass 11112222
    }
 
    virtual_ipaddress {
        172.16.10.130/24 dev eth2    #需要綁定的VIP
        172.16.10.131/24 dev eth2
    }
 
    track_script {
        monitor_oracle_status
        change_monitor_status
    }
 
    track_interface {
        eth0    #同時監(jiān)控檢測其他的網(wǎng)接口
    }
    notify_master "/usr/local/keepalived/scripts/keepalived_notify.sh master"
    notify_backup "/usr/local/keepalived/scripts/keepalived_notify.sh backup"
    notify_fault  "/usr/local/keepalived/scripts/keepalived_notify.sh fault"
    notify_stop   "/usr/local/keepalived/scripts/keepalived_notify.sh stop"
    ! notify管理腳本的定義
    ! 分別對應(yīng)keepalived轉(zhuǎn)換為master、backup、fault、stop狀態(tài)時執(zhí)行的腳本
    ! 在oracle的雙機管理中主要是依賴這些腳本實現(xiàn)資源的接管
}


keepalived監(jiān)控腳本

[root@hmdg-db1 scripts]# ls -l /usr/local/keepalived/scripts/
-rwxr-xr-x 1 root root   818 Apr 14 20:13 change_monitor_status.sh
-rw-r--r-- 1 root root    57 Apr 14 20:13 Controlfile.sql
-rw-r--r-- 1 root root  1308 Apr 14 20:13 keepalived
-rwxr-xr-x 1 root root 10549 Apr 14 23:18 keepalived_notify.sh
-rwxr-xr-x 1 root root   926 Apr 14 23:12 monitor_primary_oracle.sh
-rwxr-xr-x 1 root root   895 Apr 15 16:46 monitor.sh
-rwxr-xr-x 1 root root   895 Apr 14 20:13 monitor_standby_oracle.sh
-rw-r--r-- 1 root root  1657 Apr 15 15:13 oracle_init.sh
-rwxr-xr-x 1 root root  8441 Apr 14 20:13 notify.sh_20180413

 

關(guān)于這些keepalived腳本,由于篇幅有限我沒有全部貼到本文中,大家可以訪問我的Github倉庫找到:https://github.com/hmlinux/oracle-keepalived


l  keepalived_notify.sh             #keepalived的notify腳本,用于實現(xiàn)主備的資源自動切換

l  monitor.sh                            #keepalved的監(jiān)控腳本,監(jiān)控oracle數(shù)據(jù)庫運行狀態(tài)、共享存儲狀態(tài)

l  change_monitor_status.sh   #異常或正常檢測腳本,當(dāng)備服務(wù)器處于正常運行狀態(tài),并且處于keepalived的BACKUP狀態(tài)時,將自身的監(jiān)控腳本修改為在備機就緒時執(zhí)行都返回正常結(jié)果,主要作用時讓正常的備機可以隨時接管主服務(wù)器的資源

l  monitor_primary_oracle.sh  #處于MASTER狀態(tài)時的服務(wù)器監(jiān)控腳本

l  monitor_standby_oracle.sh  #處于BACKUP狀態(tài)時的服務(wù)器監(jiān)控腳本

l  oracle_init.sh                        #notify腳本調(diào)用oracle啟動、停止、狀態(tài)檢測命令


  • keepalived_notify.sh

#!/bin/bash
# author: hm@huangming.org
# keepalived notify script
 
#bind vip interface
interface="eth2"
 
#keepalived virtual_ipaddress
virtual_ipaddress="172.16.10.130","172.16.10.131"
 
MASTER_HOSTNAME="hmdg-db1"    #DB1
BACKUP_HOSTNAME="hmdg-db2"    #DB2
 
LOGDIR="/usr/local/keepalived/log"
LOGFILE="$LOGDIR/keepalived_haswitch.log"
TMPLOG=/tmp/notify_.log
 
sharedisk="/dev/sdb1"
sharedisk_mount_point="/oradata"
 
# oracle_datadir="/oradata/path/HMODB"
oracle_datadir="/oradata"
 
# Source oracle database instance startup/shutdown script
. /usr/local/keepalived/scripts/oracle_init.sh
 
control_files="/$oracle_datadir/$ORACLE_SID/control01.ctl","/u01/app/oracle/flash_recovery_area/$ORACLE_SID/control02.ctl","/home/oracle/rman/$ORACLE_SID/control03.ctl"
 
RETVAL=0
 
OLD_IFS="$IFS"
IFS=","
 
[ -d $LOGDIR ] || mkdir $LOGDIR
 
controlfile_backpath="/backup/oracle/control"
controlfile_back=$controlfile_backpath/control_$(date '+%Y%d%m%H%M%S')
[ -d $controlfile_backpath ] || mkdir -p $controlfile_backpath && chown -R oracle:oinstall $controlfile_backpath
 
info_log() {
    printf "$(date '+%b  %d %T %a') $HOSTNAME [keepalived_notify]: $1"
}
 
control01_ctl=`printf ${control_files[0]}`
 
backup_controlfile() {
    su - oracle << EOF
    export ORACLE_SID=$ORACLE_SID
    $ORACLE_HOME/bin/sqlplus -S "/ as sysdba"
    alter database backup controlfile to '$controlfile_back';
    exit
EOF
}
 
#runuser -l oracle -c "export ORACLE_SID=$ORACLE_SID;rman target / cmdfile=/usr/scripts/ControlfileRestore.sql"
restore_controlfile() {
    su - oracle << EOF
    export ORACLE_SID=$ORACLE_SID
    $ORACLE_HOME/bin/rman target / nocatalog
    RESTORE CONTROLFILE FROM '$control01_ctl';
    exit
EOF
}
 
ssh_p=$(netstat -ntp | awk '/sshd/{print $4}' | awk -F':' '{print $2}' | head -1)
chk_remote_node_sharedisk() {
    if [ $(hostname) == $MASTER_HOSTNAME ];then
        if ping -c1 -w2 $BACKUP_HOSTNAME &>/dev/null;then
            runuser -l oracle -c "ssh -p$ssh_p $BACKUP_HOSTNAME 2>/dev/null df | grep $sharedisk | wc -l"
        fi
    fi
    if [ $(hostname) == $BACKUP_HOSTNAME ];then
        if ping -c1 -w2 $MASTER_HOSTNAME &>/dev/null;then
            runuser -l oracle -c "ssh -p$ssh_p $MASTER_HOSTNAME 2>/dev/null df | grep $sharedisk | wc -l"
        fi
    fi
}
 
master() {
    info_log "Database Switchover To MASTER\n"
    info_log "Check remote node sharedisk mounted.\n"
    i=1
    while (($i<=30))
    do
        chk_status=$(chk_remote_node_sharedisk)
        if [ $chk_status -ge 1 ];then
            info_log "$sharedisk is already mounted on remote node or busy. checking [$i]...\n"
        else
            info_log "$sharedisk check passed.\n"
            break
        fi
        if [ $i -eq 20 ];then
            info_log "Disk status abnormal.\n"
            exit 1
        fi
        sleep 1
        i=$(($i+1))
    done
    ismount=$(df -h | grep $sharedisk | grep $sharedisk_mount_point | wc -l)
    if [ $ismount -eq 0 ];then
        info_log "mount $sharedisk on $sharedisk_mount_point\n"
        mount $sharedisk $sharedisk_mount_point
        RETVAL=$?
        if [ $RETVAL -eq 0 ];then
            #shutdown_instance
            info_log "restore controlfile 1\n"
            startup_nomount
            restore_controlfile
        else
            info_log "Error: $sharedisk cannot mount or $sharedisk_mount_point busy\n"
            exit $RETVAL
        fi
    else
        disk=$(df -h | grep $sharedisk_mount_point | awk '{print $1}')
        if [ $disk == $sharedisk ];then
            info_log "mount: $sharedisk is already mounted on $sharedisk_mount_point\n"
        else
            info_log "Warning: $sharedisk already mounted on $disk\n"
        fi
    fi
 
    status=$(check_instance_status | grep -Eio -e "\bOPEN\b" -e "\bMOUNTED\b" -e "\bSTARTED\b")
    if [ "$status" == "OPEN" ];then
        info_log "a database already open by the instance.\n"
    elif [ "$status" == "MOUNTED" ];then
        info_log "re-open database instance\n"
        open_instance | tee $TMPLOG
        opened=$(cat $TMPLOG | grep -Eio "\bDatabase altered\b")
        if [ "$opened" != "Database altered" ];then
            info_log "Error: database instance open fail!\n"
            exit 2
        fi
    elif [ "$status" == "STARTED" ];then
        info_log "alter database to mount\n"
        mount_instance | tee $TMPLOG
        mounted=$(cat $TMPLOG | grep -Eio "\bDatabase altered\b")
        if [ "$mounted" == "Database altered" ];then
            info_log "alter database to open\n"
            open_instance | tee $TMPLOG
            opened=$(cat $TMPLOG | grep -Eio "\bDatabase altered\b")
            if [ "$opened" == "Database altered" ];then
                info_log "Database opened.\n"
            else
                info_log "Database open failed\n"
                exit 4
            fi
        else
            info_log "Database mount failed\n"
            exit 3
        fi
    else
        info_log "Startup database and open instance\n"
        shutdown_instance &>/dev/null
        startup_instance | tee $TMPLOG
        started=$(cat $TMPLOG | grep -Eio "\bDatabase opened\b")
        if [ "$started" != "Database opened" ];then
            info_log "Database instance open fail.\n"
            info_log "restore controlfile 2\n"
            shutdown_instance | tee $TMPLOG
            startup_nomount | tee $TMPLOG
            restore_controlfile
            shutdown_instance | tee $TMPLOG
            startup_instance | tee $TMPLOG
            started=$(cat $TMPLOG | grep -Eio "\bDatabase opened\b")
            if [ "$started" != "Database opened" ];then
                info_log "Database restore fail!\n"
                exit 5
            else
                info_log "Database opened.\n"
            fi
        else
            info_log "Database opened.\n"
        fi
    fi
 
    info_log "Startup listener\n"
    runuser -l oracle -c "lsnrctl status &>/dev/null"
    if [ $? -eq 0 ];then
        info_log "listener already started.\n"
    else
        info_log "starting listener...\n"
        runuser -l oracle -c "lsnrctl start &>/dev/null"
        if [ $? -eq 0 ];then
            info_log "The listener startup successfully\n"
        else
            info_log "Listener start failure!\n"
        fi
    fi
echo
 
}
 
backup() {
    info_log "Database Switchover To BACKUP\n"
    ismount=$(df -h | grep $sharedisk | grep $sharedisk_mount_point | wc -l)
    if [ $ismount -ge 1 ];then
        disk=$(df -h | grep $sharedisk_mount_point | awk '{print $1}')
        if [ $disk == $sharedisk ];then
            status=$(check_instance_status | grep -Eio -e "\bOPEN\b" -e "\bMOUNTED\b" -e "\bSTARTED\b")
            if [ "$status" == "OPEN" -o "$status" == "MOUNTED" ];then
                info_log "Database instance state is mounted\n"
                info_log "Backup current controlfile.\n"
                echo -e "\nSQL> alter database backup controlfile to '$controlfile_back';\n"
                backup_controlfile
                info_log "Shutdown database instance, please wait...\n"
                shutdown_instance | tee $TMPLOG
                shuted=$(cat $TMPLOG | grep -Eio "\binstance shut down\b")
                if [ "$shuted" == "instance shut down" ];then
                    info_log "Database instance shutdown successfully.\n"
                else
                    info_log "Database instance shutdown failed.\n"
                    info_log "shutdown abort.\n"
                    shutdown_abort
                fi
            elif [ "$status" == "STARTED" ];then
                info_log "Database instance state is STARTED\n"
                info_log "Shutdown database instance, please wait...\n"
                shutdown_instance | tee $TMPLOG
                shuted=$(cat $TMPLOG | grep -Eio "\binstance shut down\b")
                if [ "$shuted" == "instance shut down" ];then
                    info_log "Database instance shutdown successfully.\n"
                else
                    info_log "Database instance shutdown failed.\n"
                    info_log "shutdown abort.\n"
                    shutdown_abort
                fi
            else
                shutdown_instance | tee $TMPLOG
                info_log "Database instance not available.\n"
            fi
 
            echo
            info_log "umount sharedisk\n"
            echo
            umount $sharedisk_mount_point && RETVAL=$?
            if [ $RETVAL -eq 0 ];then
                info_log "umount $sharedisk_mount_point success.\n"
            else
                info_log "umount $sharedisk_mount_point fail!\n"
            fi
        else
            info_log "$sharedisk is not mount on $sharedisk_mount_point or busy.\n"
        fi
    else
        info_log "$sharedisk_mount_point is no mount\n"
    fi
 
    info_log "stopping listener...\n"
    runuser -l oracle -c "lsnrctl status" &>/dev/null
    RETVAL=$?
    if [ $RETVAL -eq 0 ];then
        runuser -l oracle -c "lsnrctl stop" &>/dev/null
        RETVAL=$?
        if [ $RETVAL -eq 0 ];then
            info_log "The listener stop successfully\n"
        else
            info_log "Listener stop failure!\n"
       fi
    else
        info_log "listener is not started.\n"
    fi
    echo
}
 
notify_master() {
    echo -e "\n-------------------------------------------------------------------------------"
    echo "`date '+%b  %d %T %a'` $(hostname) [keepalived_notify]: Transition to $1 STATE";
    echo "`date '+%b  %d %T %a'` $(hostname) [keepalived_notify]: Setup the VIP on $interface $virtual_ipaddress";
}
 
notify_backup() {
    echo -e "\n-------------------------------------------------------------------------------"
    echo "`date '+%b  %d %T %a'` $HOSTNAME [keepalived_notify]: Transition to $1 STATE";
    echo "`date '+%b  %d %T %a'` $HOSTNAME [keepalived_notify]: removing the VIP on $interface for $virtual_ipaddress";
}
 
case $1 in
        master)
                notify_master MASTER | tee -a $LOGFILE
                master | tee -a $LOGFILE
        ;;
        backup)
                notify_backup BACKUP | tee -a $LOGFILE
                backup | tee -a $LOGFILE
        ;;
        fault)
                notify_backup FAULT | tee -a $LOGFILE
                backup | tee -a $LOGFILE
        ;;
        stop)
                notify_backup STOP | tee -a $LOGFILE
                /etc/init.d/keepalived start
                #sleep 6 && backup | tee -a $LOGFILE
        ;;
        *)
                echo "Usage: `basename $0` {master|backup|fault|stop}"
                RETVAL=1
        ;;
esac
exit $RETVAL


手動執(zhí)行notify切換腳本

l  將主服務(wù)器切換為BACKUP狀態(tài)

執(zhí)行./keepalived_notify.sh backup

[root@hmdg-db1 scripts]# ./keepalived_notify.sh backup
 
-------------------------------------------------------------------------------
Apr  15 17:23:05 Sun hmdg-db1 [keepalived_notify]: Transition to BACKUP STATE
Apr  15 17:23:05 Sun hmdg-db1 [keepalived_notify]: removing the VIP on eth2 for 172.16.10.130,172.16.10.131
Apr  15 17:23:05 Sun hmdg-db1 [keepalived_notify]: Database Switchover To BACKUP
Apr  15 17:23:05 Sun hmdg-db1 [keepalived_notify]: /oradata is no mount
Apr  15 17:23:05 Sun hmdg-db1 [keepalived_notify]: stopping listener...
Apr  15 17:23:05 Sun hmdg-db1 [keepalived_notify]: listener is not started.

觀察執(zhí)行腳本的輸出結(jié)果,這是由于在本機上并沒有啟動oracle實例,所以腳本最終提示本機并沒有啟動oracle數(shù)據(jù)庫實例


l  將主服務(wù)器切換為MASTER狀態(tài)

執(zhí)行./keepalived_notify.sh master

[root@hmdg-db1 scripts]# ./keepalived_notify.sh master
 
-------------------------------------------------------------------------------
Apr  15 17:23:43 Sun hmdg-db1 [keepalived_notify]: Transition to MASTER STATE
Apr  15 17:23:43 Sun hmdg-db1 [keepalived_notify]: Setup the VIP on eth2 172.16.10.130,172.16.10.131
Apr  15 17:23:43 Sun hmdg-db1 [keepalived_notify]: Database Switchover To MASTER
Apr  15 17:23:43 Sun hmdg-db1 [keepalived_notify]: Check remote node sharedisk mounted.
Apr  15 17:23:43 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 check passed.
Apr  15 17:23:43 Sun hmdg-db1 [keepalived_notify]: mount /dev/sdb1 on /oradata
Apr  15 17:23:43 Sun hmdg-db1 [keepalived_notify]: restore controlfile 1
ORACLE instance started.
 
Total System Global Area 1603411968 bytes
Fixed Size                 2213776 bytes
Variable Size          1056966768 bytes
Database Buffers     536870912 bytes
Redo Buffers             7360512 bytes
 
Recovery Manager: Release 11.2.0.1.0 - Production on Sun Apr 15 17:23:44 2018
 
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
 
connected to target database: HMODB (not mounted)
using target database control file instead of recovery catalog
 
RMAN>
Starting restore at 15-APR-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=572 device type=DISK
 
channel ORA_DISK_1: copied control file copy
output file name=/oradata/HMODB/control01.ctl
output file name=/u01/app/oracle/flash_recovery_area/HMODB/control02.ctl
output file name=/home/oracle/rman/HMODB/control03.ctl
Finished restore at 15-APR-18
 
RMAN>
 
Recovery Manager complete.
Apr  15 17:23:46 Sun hmdg-db1 [keepalived_notify]: alter database to mount
 
Database altered.
 
Apr  15 17:23:50 Sun hmdg-db1 [keepalived_notify]: alter database to open
 
Database altered.
 
Apr  15 17:23:57 Sun hmdg-db1 [keepalived_notify]: Database opened.
Apr  15 17:23:57 Sun hmdg-db1 [keepalived_notify]: Startup listener
Apr  15 17:23:57 Sun hmdg-db1 [keepalived_notify]: starting listener...
Apr  15 17:23:57 Sun hmdg-db1 [keepalived_notify]: The listener startup successfully

觀察執(zhí)行腳本的輸出結(jié)果

1、腳本接收轉(zhuǎn)換到MASTER信息

2、首先提示綁定的VIP

3、然后檢測遠(yuǎn)程備用節(jié)點的磁盤是否掛載,或本機是否掛載了磁盤,檢測成功則把磁盤掛載

4、啟動數(shù)據(jù)庫到nomount狀態(tài),并恢復(fù)控制文件

5、啟動數(shù)據(jù)庫實例到open狀態(tài)

6、啟動數(shù)據(jù)庫監(jiān)聽,切換完成

 

注意:如果使用系統(tǒng)命令手動切換,應(yīng)該要保證正在運行oracle服務(wù)的主節(jié)點先正常關(guān)閉,并且卸載共享存儲之后,再啟動備用節(jié)點的oracle服務(wù)(即不能同時掛載共享存儲)


l  再次將主服務(wù)器切換到BACKUP狀態(tài)

執(zhí)行./keepalived_notify.sh backup

[root@hmdg-db1 scripts]# ./keepalived_notify.sh backup
 
-------------------------------------------------------------------------------
Apr  15 17:34:54 Sun hmdg-db1 [keepalived_notify]: Transition to BACKUP STATE
Apr  15 17:34:54 Sun hmdg-db1 [keepalived_notify]: removing the VIP on eth2 for 172.16.10.130,172.16.10.131
Apr  15 17:34:54 Sun hmdg-db1 [keepalived_notify]: Database Switchover To BACKUP
Apr  15 17:34:55 Sun hmdg-db1 [keepalived_notify]: Database instance state is mounted
Apr  15 17:34:55 Sun hmdg-db1 [keepalived_notify]: Backup current controlfile.
 
SQL> alter database backup controlfile to '/backup/oracle/control/control_20181504173454';
 
 
Database altered.
 
Apr  15 17:34:55 Sun hmdg-db1 [keepalived_notify]: Shutdown database instance, please wait...
Database closed.
Database dismounted.
ORACLE instance shut down.
Apr  15 17:35:04 Sun hmdg-db1 [keepalived_notify]: Database instance shutdown successfully.
 
Apr  15 17:35:04 Sun hmdg-db1 [keepalived_notify]: umount sharedisk
 
Apr  15 17:35:05 Sun hmdg-db1 [keepalived_notify]: umount /oradata success.
Apr  15 17:35:05 Sun hmdg-db1 [keepalived_notify]: stopping listener...
Apr  15 17:35:08 Sun hmdg-db1 [keepalived_notify]: The listener stop successfully

觀察執(zhí)行腳本的輸出結(jié)果

1、 腳本接收轉(zhuǎn)換到BACKUP信息

2、 首先移除VIP(由keepalived綁定到主機上浮動IP地址,同時也是對外提供服務(wù)的IP地址),實際上是由keepalived檢測到異?;虮旧淼姆?wù)器不可用時自動剔除VIP

3、 備份控制文件到/backup/oracle/control/目錄下

4、 正常關(guān)閉數(shù)據(jù)庫實例

5、 卸載共享存儲

6、 關(guān)閉數(shù)據(jù)庫監(jiān)聽程序


l  notify腳本切換演示

如果備機主動切換到MASTER狀態(tài)時,腳本首先或檢測對方磁盤是否umount,如果沒有則最多等待20秒,提示異常并正常推出切換到MASTER的請求

[root@hmdg-db1 scripts]# ./keepalived_notify.sh master
 
-------------------------------------------------------------------------------
Apr  15 17:40:08 Sun hmdg-db1 [keepalived_notify]: Transition to MASTER STATE
Apr  15 17:40:08 Sun hmdg-db1 [keepalived_notify]: Setup the VIP on eth2 172.16.10.130,172.16.10.131
Apr  15 17:40:08 Sun hmdg-db1 [keepalived_notify]: Database Switchover To MASTER
Apr  15 17:40:08 Sun hmdg-db1 [keepalived_notify]: Check remote node sharedisk mounted.
Apr  15 17:40:08 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [1]...
Apr  15 17:40:09 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [2]...
Apr  15 17:40:10 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [3]...
Apr  15 17:40:12 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [4]...
Apr  15 17:40:13 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [5]...
Apr  15 17:40:14 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [6]...
Apr  15 17:40:15 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [7]...
Apr  15 17:40:16 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [8]...
Apr  15 17:40:17 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [9]...
Apr  15 17:40:18 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [10]...
Apr  15 17:40:20 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [11]...
Apr  15 17:40:21 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [12]...
Apr  15 17:40:22 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [13]...
Apr  15 17:40:23 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [14]...
Apr  15 17:40:24 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [15]...
Apr  15 17:40:25 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [16]...
Apr  15 17:40:26 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [17]...
Apr  15 17:40:27 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [18]...
Apr  15 17:40:29 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [19]...
Apr  15 17:40:30 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [20]...
Apr  15 17:40:30 Sun hmdg-db1 [keepalived_notify]: Disk status abnormal.

這時如果需要手動切換,則需要先將遠(yuǎn)程備用節(jié)點的服務(wù)關(guān)閉并umount存儲之后,才能正常切換

[root@hmdg-db1 scripts]# ./keepalived_notify.sh master
 
-------------------------------------------------------------------------------
Apr  15 17:45:29 Sun hmdg-db1 [keepalived_notify]: Transition to MASTER STATE
Apr  15 17:45:29 Sun hmdg-db1 [keepalived_notify]: Setup the VIP on eth2 172.16.10.130,172.16.10.131
Apr  15 17:45:29 Sun hmdg-db1 [keepalived_notify]: Database Switchover To MASTER
Apr  15 17:45:29 Sun hmdg-db1 [keepalived_notify]: Check remote node sharedisk mounted.
Apr  15 17:45:29 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [1]...
Apr  15 17:45:30 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [2]...
Apr  15 17:45:31 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [3]...
Apr  15 17:45:32 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [4]...
Apr  15 17:45:33 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [5]...
Apr  15 17:45:35 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [6]...
Apr  15 17:45:36 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [7]...
Apr  15 17:45:37 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [8]...
Apr  15 17:45:38 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [9]...
Apr  15 17:45:39 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [10]...
Apr  15 17:45:40 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [11]...
Apr  15 17:45:41 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [12]...
Apr  15 17:45:42 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [13]...
Apr  15 17:45:44 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 check passed.
Apr  15 17:45:44 Sun hmdg-db1 [keepalived_notify]: mount /dev/sdb1 on /oradata
Apr  15 17:45:44 Sun hmdg-db1 [keepalived_notify]: restore controlfile 1
ORACLE instance started.
 
Total System Global Area 1603411968 bytes
Fixed Size                 2213776 bytes
Variable Size          1056966768 bytes
Database Buffers     536870912 bytes
Redo Buffers             7360512 bytes
 
Recovery Manager: Release 11.2.0.1.0 - Production on Sun Apr 15 17:45:45 2018
 
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
 
connected to target database: HMODB (not mounted)
using target database control file instead of recovery catalog
 
RMAN>
Starting restore at 15-APR-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=572 device type=DISK
 
channel ORA_DISK_1: copied control file copy
output file name=/oradata/HMODB/control01.ctl
output file name=/u01/app/oracle/flash_recovery_area/HMODB/control02.ctl
output file name=/home/oracle/rman/HMODB/control03.ctl
Finished restore at 15-APR-18
 
RMAN>
 
Recovery Manager complete.
Apr  15 17:45:46 Sun hmdg-db1 [keepalived_notify]: alter database to mount
 
Database altered.
 
Apr  15 17:45:51 Sun hmdg-db1 [keepalived_notify]: alter database to open
 
Database altered.
 
Apr  15 17:45:58 Sun hmdg-db1 [keepalived_notify]: Database opened.
Apr  15 17:45:58 Sun hmdg-db1 [keepalived_notify]: Startup listener
Apr  15 17:45:58 Sun hmdg-db1 [keepalived_notify]: starting listener...
Apr  15 17:45:58 Sun hmdg-db1 [keepalived_notify]: The listener startup successfully



啟動keepalived服務(wù)接管Oracle服務(wù)

啟動keepalived服務(wù)時,keepalived首先進(jìn)行資源檢測,并根據(jù)權(quán)值設(shè)定MASTER角色

  • keepalived接管的資源:Oracle實例、存儲、VIP


1、啟動主服務(wù)器DB1的keepalived

##啟動keepalived
[root@hmdg-db1 scripts]# /etc/init.d/keepalived start

##設(shè)置開機啟動
[root@hmdg-db1 scripts]# chkconfig keepalived on

2、查看主服務(wù)器的keepalived系統(tǒng)日志

[root@hmdg-db1 scripts]# tail -f /var/log/messages


Apr 15 17:51:25 hmdg-db1 Keepalived_vrrp[82072]: Registering Kernel netlink reflector
Apr 15 17:51:25 hmdg-db1 Keepalived_vrrp[82072]: Registering Kernel netlink command channel
Apr 15 17:51:25 hmdg-db1 Keepalived_vrrp[82072]: Registering gratuitous ARP shared channel
Apr 15 17:51:25 hmdg-db1 Keepalived_healthcheckers[82071]: Using LinkWatch kernel netlink reflector...
Apr 15 17:51:25 hmdg-db1 Keepalived_vrrp[82072]: Opening file '/usr/local/keepalived/etc/keepalived/keepalived.conf'.
Apr 15 17:51:25 hmdg-db1 Keepalived_vrrp[82072]: VRRP_Instance(Oracle_HA_1) removing protocol VIPs.
Apr 15 17:51:25 hmdg-db1 Keepalived_vrrp[82072]: SECURITY VIOLATION - scripts are being executed but script_security not enabled.
Apr 15 17:51:25 hmdg-db1 Keepalived_vrrp[82072]: Sync group ORACLE_HA_GROUP has only 1 virtual router(s) - removing
Apr 15 17:51:25 hmdg-db1 Keepalived_vrrp[82072]: Using LinkWatch kernel netlink reflector...
Apr 15 17:51:25 hmdg-db1 Keepalived_vrrp[82072]: VRRP_Instance(Oracle_HA_1) Entering BACKUP STATE
Apr 15 17:51:25 hmdg-db1 Keepalived_vrrp[82072]: VRRP sockpool: [ifindex(3), proto(112), unicast(0), fd(10,11)]
Apr 15 17:51:25 hmdg-db1 Keepalived_vrrp[82072]: VRRP_Script(change_monitor_status) succeeded
Apr 15 17:51:25 hmdg-db1 Keepalived_vrrp[82072]: VRRP_Script(monitor_oracle_status) succeeded
Apr 15 17:51:27 hmdg-db1 Keepalived_vrrp[82072]: VRRP_Instance(Oracle_HA_1) Changing effective priority from 100 to 120
Apr 15 17:51:31 hmdg-db1 Keepalived_vrrp[82072]: VRRP_Instance(Oracle_HA_1) Transition to MASTER STATE
Apr 15 17:51:33 hmdg-db1 Keepalived_vrrp[82072]: VRRP_Instance(Oracle_HA_1) Entering MASTER STATE
Apr 15 17:51:33 hmdg-db1 Keepalived_vrrp[82072]: VRRP_Instance(Oracle_HA_1) setting protocol VIPs.
Apr 15 17:51:33 hmdg-db1 Keepalived_vrrp[82072]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 17:51:33 hmdg-db1 Keepalived_healthcheckers[82071]: Netlink reflector reports IP 172.16.10.130 added
Apr 15 17:51:33 hmdg-db1 Keepalived_healthcheckers[82071]: Netlink reflector reports IP 172.16.10.131 added
Apr 15 17:51:33 hmdg-db1 Keepalived_vrrp[82072]: VRRP_Instance(Oracle_HA_1) Sending/queueing gratuitous ARPs on eth2 for 172.16.10.130
Apr 15 17:51:33 hmdg-db1 Keepalived_vrrp[82072]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 17:51:33 hmdg-db1 Keepalived_vrrp[82072]: VRRP_Instance(Oracle_HA_1) Sending/queueing gratuitous ARPs on eth2 for 172.16.10.131
Apr 15 17:51:33 hmdg-db1 Keepalived_vrrp[82072]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 17:51:33 hmdg-db1 Keepalived_vrrp[82072]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 17:51:33 hmdg-db1 Keepalived_vrrp[82072]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 17:51:33 hmdg-db1 Keepalived_vrrp[82072]: Sending gratuitous ARP on eth2 for 172.16.10.131


3、啟動備服務(wù)器DB2的keepalived

##啟動keepalived
[root@hmdg-db2 scripts]# /etc/init.d/keepalived start

##設(shè)置開機啟動
[root@hmdg-db2 scripts]# chkconfig keepalived on

4、查看備服務(wù)器的keepalived系統(tǒng)日志

Apr 15 17:51:41 hmdg-db2 Keepalived[71709]: Starting Keepalived v1.3.2 (04/14,2018)
Apr 15 17:51:41 hmdg-db2 Keepalived[71709]: WARNING - default user 'keepalived_script' for script execution does not exist - please create.
Apr 15 17:51:41 hmdg-db2 Keepalived[71709]: Opening file '/usr/local/keepalived/etc/keepalived/keepalived.conf'.
Apr 15 17:51:41 hmdg-db2 Keepalived[71710]: Starting Healthcheck child process, pid=71711
Apr 15 17:51:41 hmdg-db2 Keepalived[71710]: Starting VRRP child process, pid=71712
Apr 15 17:51:41 hmdg-db2 Keepalived_healthcheckers[71711]: Netlink reflector reports IP 192.168.6.26 added
Apr 15 17:51:41 hmdg-db2 Keepalived_healthcheckers[71711]: Netlink reflector reports IP 172.16.10.26 added
Apr 15 17:51:41 hmdg-db2 Keepalived_healthcheckers[71711]: Netlink reflector reports IP fe80::20c:29ff:fedd:d175 added
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: Netlink reflector reports IP 192.168.6.26 added
Apr 15 17:51:41 hmdg-db2 Keepalived_healthcheckers[71711]: Netlink reflector reports IP fe80::20c:29ff:fedd:d17f added
Apr 15 17:51:41 hmdg-db2 Keepalived_healthcheckers[71711]: Netlink reflector reports IP fe80::20c:29ff:fedd:d189 added
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: Netlink reflector reports IP 172.16.10.26 added
Apr 15 17:51:41 hmdg-db2 Keepalived_healthcheckers[71711]: Netlink reflector reports IP fe80::20c:29ff:fedd:d193 added
Apr 15 17:51:41 hmdg-db2 Keepalived_healthcheckers[71711]: Registering Kernel netlink reflector
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: Netlink reflector reports IP fe80::20c:29ff:fedd:d175 added
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: Netlink reflector reports IP fe80::20c:29ff:fedd:d17f added
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: Netlink reflector reports IP fe80::20c:29ff:fedd:d189 added
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: Netlink reflector reports IP fe80::20c:29ff:fedd:d193 added
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: Registering Kernel netlink reflector
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: Registering Kernel netlink command channel
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: Registering gratuitous ARP shared channel
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: Opening file '/usr/local/keepalived/etc/keepalived/keepalived.conf'.
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: VRRP_Instance(Oracle_HA_1) removing protocol VIPs.
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: SECURITY VIOLATION - scripts are being executed but script_security not enabled.
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: Sync group ORACLE_HA_GROUP has only 1 virtual router(s) - removing
Apr 15 17:51:41 hmdg-db2 Keepalived_healthcheckers[71711]: Registering Kernel netlink command channel
Apr 15 17:51:41 hmdg-db2 Keepalived_healthcheckers[71711]: Opening file '/usr/local/keepalived/etc/keepalived/keepalived.conf'.
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: Using LinkWatch kernel netlink reflector...
Apr 15 17:51:41 hmdg-db2 Keepalived_healthcheckers[71711]: Using LinkWatch kernel netlink reflector...
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: VRRP_Instance(Oracle_HA_1) Entering BACKUP STATE
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: VRRP sockpool: [ifindex(3), proto(112), unicast(0), fd(10,11)]
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: pid 71721 exited with status 1
Apr 15 17:51:41 hmdg-db2 Keepalived_vrrp[71712]: VRRP_Script(change_monitor_status) succeeded
Apr 15 17:52:01 hmdg-db2 Keepalived_vrrp[71712]: VRRP_Script(monitor_oracle_status) succeeded
Apr 15 17:52:01 hmdg-db2 Keepalived_vrrp[71712]: VRRP_Instance(Oracle_HA_1) Changing effective priority from 90 to 110


5、主備Oracle、VIP、磁盤服務(wù)狀態(tài)檢查

##DB1
[root@hmdg-db1 scripts]# ps -ef | grep ora_
oracle    82439      1  0 17:51 ?        00:00:00 ora_pmon_HMODB
oracle    82441      1  0 17:51 ?        00:00:00 ora_vktm_HMODB
oracle    82445      1  0 17:51 ?        00:00:00 ora_gen0_HMODB
oracle    82447      1  0 17:51 ?        00:00:00 ora_diag_HMODB
oracle    82449      1  0 17:51 ?        00:00:00 ora_dbrm_HMODB
oracle    82451      1  0 17:51 ?        00:00:00 ora_psp0_HMODB
oracle    82453      1  0 17:51 ?        00:00:00 ora_dia0_HMODB
oracle    82455      1  0 17:51 ?        00:00:00 ora_mman_HMODB
oracle    82457      1  0 17:51 ?        00:00:00 ora_dbw0_HMODB
oracle    82459      1  0 17:51 ?        00:00:00 ora_lgwr_HMODB
oracle    82461      1  0 17:51 ?        00:00:00 ora_ckpt_HMODB
oracle    82463      1  0 17:51 ?        00:00:00 ora_smon_HMODB
oracle    82465      1  0 17:51 ?        00:00:00 ora_reco_HMODB
oracle    82467      1  0 17:51 ?        00:00:00 ora_mmon_HMODB
oracle    82469      1  0 17:51 ?        00:00:00 ora_mmnl_HMODB
oracle    82471      1  0 17:51 ?        00:00:00 ora_d000_HMODB
oracle    82473      1  0 17:51 ?        00:00:00 ora_s000_HMODB
oracle    82638      1  0 17:51 ?        00:00:00 ora_arc0_HMODB
oracle    82653      1  0 17:51 ?        00:00:00 ora_arc1_HMODB
oracle    82655      1  0 17:51 ?        00:00:00 ora_arc2_HMODB
oracle    82657      1  0 17:51 ?        00:00:00 ora_arc3_HMODB
oracle    82755      1  0 17:51 ?        00:00:00 ora_qmnc_HMODB
oracle    82807      1  0 17:51 ?        00:00:00 ora_cjq0_HMODB
oracle    82835      1  0 17:51 ?        00:00:00 ora_vkrm_HMODB
oracle    82863      1  0 17:51 ?        00:00:00 ora_q000_HMODB
oracle    82865      1  0 17:51 ?        00:00:00 ora_q001_HMODB
oracle    84099      1  1 17:54 ?        00:00:00 ora_j000_HMODB
oracle    84101      1  0 17:54 ?        00:00:00 ora_j001_HMODB
root      84268   3823  0 17:54 pts/2    00:00:00 grep ora_
 
 
[root@hmdg-db1 scripts]# df -Th
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/sda3      ext4    50G   19G   29G  40% /
tmpfs          tmpfs  3.9G  909M  3.0G  24% /dev/shm
/dev/sda1      ext4   190M   40M  141M  22% /boot
/dev/sdb1      ext4    30G  6.0G   22G  22% /oradata
 
[root@hmdg-db1 scripts]# ip addr show dev eth2
3: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:59:d5:91 brd ff:ff:ff:ff:ff:ff
    inet 172.16.10.25/24 brd 172.16.10.255 scope global eth2
    inet 172.16.10.130/24 scope global secondary eth2
    inet 172.16.10.131/24 scope global secondary eth2
    inet6 fe80::20c:29ff:fe59:d591/64 scope link
       valid_lft forever preferred_lft forever



##DB2
[root@hmdg-db2 scripts]# ps -ef | grep ora_
root      73251  31390  0 17:55 pts/2    00:00:00 grep ora_
 
 
[root@hmdg-db2 scripts]# df -Th
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/sda3      ext4    50G   18G   30G  37% /
tmpfs          tmpfs  3.9G     0  3.9G   0% /dev/shm
/dev/sda1      ext4   190M   40M  141M  22% /boot
 
 
[root@hmdg-db2 scripts]# ip addr show dev eth2
3: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:dd:d1:7f brd ff:ff:ff:ff:ff:ff
    inet 172.16.10.26/24 brd 172.16.10.255 scope global eth2
    inet6 fe80::20c:29ff:fedd:d17f/64 scope link
       valid_lft forever preferred_lft forever


測試Keepalived故障切換

  • 當(dāng)主服務(wù)故障時的切換狀態(tài)

      停止或重啟主服務(wù)器的keepalibed服務(wù)


  • 主服務(wù)器DB1

##系統(tǒng)日志
Apr 15 18:08:02 hmdg-db1 Keepalived[89311]: Stopping
Apr 15 18:08:02 hmdg-db1 Keepalived_healthcheckers[89313]: Stopped
Apr 15 18:08:02 hmdg-db1 Keepalived_vrrp[89314]: VRRP_Instance(Oracle_HA_1) sent 0 priority
Apr 15 18:08:02 hmdg-db1 Keepalived_vrrp[89314]: VRRP_Instance(Oracle_HA_1) removing protocol VIPs.
Apr 15 18:08:03 hmdg-db1 Keepalived_vrrp[89314]: Stopped
Apr 15 18:08:03 hmdg-db1 Keepalived[89311]: Stopped Keepalived v1.3.2 (04/14,2018)


##nitify腳本的輸出日志
-------------------------------------------------------------------------------
Apr  15 18:08:03 Sun hmdg-db1 [keepalived_notify]: Transition to STOP STATE
Apr  15 18:08:03 Sun hmdg-db1 [keepalived_notify]: removing the VIP on eth2 for 172.16.10.130,172.16.10.131
Apr  15 18:08:09 Sun hmdg-db1 [keepalived_notify]: Database Switchover To BACKUP
Apr  15 18:08:09 Sun hmdg-db1 [keepalived_notify]: Database instance state is mounted
Apr  15 18:08:09 Sun hmdg-db1 [keepalived_notify]: Backup current controlfile.
 
SQL> alter database backup controlfile to '/backup/oracle/control/control_20181504180803';
 
 
Database altered.
 
Apr  15 18:08:09 Sun hmdg-db1 [keepalived_notify]: Shutdown database instance, please wait...
Database closed.
Database dismounted.
ORACLE instance shut down.
Apr  15 18:08:18 Sun hmdg-db1 [keepalived_notify]: Database instance shutdown successfully.
 
Apr  15 18:08:18 Sun hmdg-db1 [keepalived_notify]: umount sharedisk
 
Apr  15 18:08:18 Sun hmdg-db1 [keepalived_notify]: umount /oradata success.
Apr  15 18:08:18 Sun hmdg-db1 [keepalived_notify]: stopping listener...
Apr  15 18:08:19 Sun hmdg-db1 [keepalived_notify]: The listener stop successfully


##服務(wù)資源檢查
[root@hmdg-db1 scripts]# ps -ef | grep ora_
root      90758   2451  0 18:09 pts/0    00:00:00 grep ora_
[root@hmdg-db1 scripts]# df -Th
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/sda3      ext4    50G   19G   29G  40% /
tmpfs          tmpfs  3.9G     0  3.9G   0% /dev/shm
/dev/sda1      ext4   190M   40M  141M  22% /boot
[root@hmdg-db1 scripts]# ip addr show dev eth2
3: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:59:d5:91 brd ff:ff:ff:ff:ff:ff
    inet 172.16.10.25/24 brd 172.16.10.255 scope global eth2
    inet6 fe80::20c:29ff:fe59:d591/64 scope link
       valid_lft forever preferred_lft forever

由于主服務(wù)的keepalived異常,keepalived實例組將會重新分配MASTER角色,并將資源轉(zhuǎn)移到BACKUP上(即重新選舉后新的MASTER)


  • 備服務(wù)器DB2

##系統(tǒng)日志
Apr 15 18:08:03 hmdg-db2 Keepalived_vrrp[77811]: VRRP_Instance(Oracle_HA_1) Transition to MASTER STATE
Apr 15 18:08:05 hmdg-db2 Keepalived_vrrp[77811]: VRRP_Instance(Oracle_HA_1) Entering MASTER STATE
Apr 15 18:08:05 hmdg-db2 Keepalived_vrrp[77811]: VRRP_Instance(Oracle_HA_1) setting protocol VIPs.
Apr 15 18:08:05 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:08:05 hmdg-db2 Keepalived_vrrp[77811]: VRRP_Instance(Oracle_HA_1) Sending/queueing gratuitous ARPs on eth2 for 172.16.10.130
Apr 15 18:08:05 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:08:05 hmdg-db2 Keepalived_vrrp[77811]: VRRP_Instance(Oracle_HA_1) Sending/queueing gratuitous ARPs on eth2 for 172.16.10.131
Apr 15 18:08:05 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:08:05 hmdg-db2 Keepalived_healthcheckers[77810]: Netlink reflector reports IP 172.16.10.130 added
Apr 15 18:08:05 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:08:05 hmdg-db2 Keepalived_healthcheckers[77810]: Netlink reflector reports IP 172.16.10.131 added
Apr 15 18:08:05 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:08:05 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:08:05 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:08:05 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:08:05 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:08:05 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:08:10 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:08:10 hmdg-db2 Keepalived_vrrp[77811]: VRRP_Instance(Oracle_HA_1) Sending/queueing gratuitous ARPs on eth2 for 172.16.10.130
Apr 15 18:08:10 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:08:10 hmdg-db2 Keepalived_vrrp[77811]: VRRP_Instance(Oracle_HA_1) Sending/queueing gratuitous ARPs on eth2 for 172.16.10.131
Apr 15 18:08:10 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:08:10 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:08:10 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:08:10 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:08:10 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:08:10 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:08:10 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:08:10 hmdg-db2 Keepalived_vrrp[77811]: Sending gratuitous ARP on eth2 for 172.16.10.131



##notify腳本日志
-------------------------------------------------------------------------------
Apr  15 18:08:05 Sun hmdg-db2 [keepalived_notify]: Transition to MASTER STATE
Apr  15 18:08:05 Sun hmdg-db2 [keepalived_notify]: Setup the VIP on eth2 172.16.10.130,172.16.10.131
Apr  15 18:08:05 Sun hmdg-db2 [keepalived_notify]: Database Switchover To MASTER
Apr  15 18:08:05 Sun hmdg-db2 [keepalived_notify]: Check remote node sharedisk mounted.
Apr  15 18:08:05 Sun hmdg-db2 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [1]...
Apr  15 18:08:06 Sun hmdg-db2 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [2]...
Apr  15 18:08:08 Sun hmdg-db2 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [3]...
Apr  15 18:08:09 Sun hmdg-db2 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [4]...
Apr  15 18:08:10 Sun hmdg-db2 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [5]...
Apr  15 18:08:11 Sun hmdg-db2 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [6]...
Apr  15 18:08:12 Sun hmdg-db2 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [7]...
Apr  15 18:08:13 Sun hmdg-db2 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [8]...
Apr  15 18:08:14 Sun hmdg-db2 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [9]...
Apr  15 18:08:15 Sun hmdg-db2 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [10]...
Apr  15 18:08:17 Sun hmdg-db2 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [11]...
Apr  15 18:08:18 Sun hmdg-db2 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [12]...
Apr  15 18:08:19 Sun hmdg-db2 [keepalived_notify]: /dev/sdb1 check passed.
Apr  15 18:08:19 Sun hmdg-db2 [keepalived_notify]: mount /dev/sdb1 on /oradata
Apr  15 18:08:19 Sun hmdg-db2 [keepalived_notify]: restore controlfile 1
ORACLE instance started.
 
Total System Global Area 1603411968 bytes
Fixed Size                 2213776 bytes
Variable Size          1056966768 bytes
Database Buffers     536870912 bytes
Redo Buffers             7360512 bytes
 
Recovery Manager: Release 11.2.0.1.0 - Production on Sun Apr 15 18:08:20 2018
 
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
 
connected to target database: HMODB (not mounted)
using target database control file instead of recovery catalog
 
RMAN>
Starting restore at 15-APR-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=572 device type=DISK
 
channel ORA_DISK_1: copied control file copy
output file name=/oradata/HMODB/control01.ctl
output file name=/u01/app/oracle/flash_recovery_area/HMODB/control02.ctl
output file name=/home/oracle/rman/HMODB/control03.ctl
Finished restore at 15-APR-18
 
RMAN>
 
Recovery Manager complete.
Apr  15 18:08:22 Sun hmdg-db2 [keepalived_notify]: alter database to mount
 
Database altered.
 
Apr  15 18:08:26 Sun hmdg-db2 [keepalived_notify]: alter database to open
 
Database altered.
 
Apr  15 18:08:33 Sun hmdg-db2 [keepalived_notify]: Database opened.
Apr  15 18:08:33 Sun hmdg-db2 [keepalived_notify]: Startup listener
Apr  15 18:08:33 Sun hmdg-db2 [keepalived_notify]: starting listener...
Apr  15 18:08:33 Sun hmdg-db2 [keepalived_notify]: The listener startup successfully


##服務(wù)檢查
[root@hmdg-db2 scripts]# ps -ef | grep ora_
oracle    78632      1  0 18:08 ?        00:00:00 ora_pmon_HMODB
oracle    78634      1  0 18:08 ?        00:00:00 ora_vktm_HMODB
oracle    78638      1  0 18:08 ?        00:00:00 ora_gen0_HMODB
oracle    78640      1  0 18:08 ?        00:00:00 ora_diag_HMODB
oracle    78642      1  0 18:08 ?        00:00:00 ora_dbrm_HMODB
oracle    78644      1  0 18:08 ?        00:00:00 ora_psp0_HMODB
oracle    78646      1  0 18:08 ?        00:00:00 ora_dia0_HMODB
oracle    78648      1  0 18:08 ?        00:00:00 ora_mman_HMODB
oracle    78650      1  0 18:08 ?        00:00:00 ora_dbw0_HMODB
oracle    78652      1  0 18:08 ?        00:00:00 ora_lgwr_HMODB
oracle    78654      1  0 18:08 ?        00:00:00 ora_ckpt_HMODB
oracle    78656      1  0 18:08 ?        00:00:00 ora_smon_HMODB
oracle    78658      1  0 18:08 ?        00:00:00 ora_reco_HMODB
oracle    78660      1  0 18:08 ?        00:00:00 ora_mmon_HMODB
oracle    78662      1  0 18:08 ?        00:00:00 ora_mmnl_HMODB
oracle    78664      1  0 18:08 ?        00:00:00 ora_d000_HMODB
oracle    78666      1  0 18:08 ?        00:00:00 ora_s000_HMODB
oracle    78844      1  0 18:08 ?        00:00:00 ora_arc0_HMODB
oracle    78847      1  0 18:08 ?        00:00:00 ora_arc1_HMODB
oracle    78849      1  0 18:08 ?        00:00:00 ora_arc2_HMODB
oracle    78851      1  0 18:08 ?        00:00:00 ora_arc3_HMODB
oracle    78879      1  0 18:08 ?        00:00:00 ora_qmnc_HMODB
oracle    78968      1  0 18:08 ?        00:00:00 ora_cjq0_HMODB
oracle    79031      1  0 18:08 ?        00:00:00 ora_vkrm_HMODB
oracle    79059      1  0 18:08 ?        00:00:00 ora_q000_HMODB
oracle    79061      1  0 18:08 ?        00:00:00 ora_q001_HMODB
oracle    81652      1  0 18:13 ?        00:00:00 ora_smco_HMODB
oracle    81667      1  0 18:13 ?        00:00:00 ora_w000_HMODB
root      81808  31390  0 18:13 pts/2    00:00:00 grep ora_
[root@hmdg-db2 scripts]# df -Th
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/sda3      ext4    50G   18G   30G  37% /
tmpfs          tmpfs  3.9G  909M  3.0G  24% /dev/shm
/dev/sda1      ext4   190M   40M  141M  22% /boot
/dev/sdb1      ext4    30G  6.0G   22G  22% /oradata
[root@hmdg-db2 scripts]# ip addr show dev eth2
3: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:dd:d1:7f brd ff:ff:ff:ff:ff:ff
    inet 172.16.10.26/24 brd 172.16.10.255 scope global eth2
    inet 172.16.10.130/24 scope global secondary eth2
    inet 172.16.10.131/24 scope global secondary eth2
    inet6 fe80::20c:29ff:fedd:d17f/64 scope link
       valid_lft forever preferred_lft forever


  • 測試當(dāng)主服務(wù)恢復(fù)后備服務(wù)器故障的切換狀態(tài)


  • 首先將DB1的Keepalived服務(wù)啟動

Apr 15 18:15:14 hmdg-db1 Keepalived_vrrp[90792]: Opening file '/usr/local/keepalived/etc/keepalived/keepalived.conf'.
Apr 15 18:15:14 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Instance(Oracle_HA_1) removing protocol VIPs.
Apr 15 18:15:14 hmdg-db1 Keepalived_vrrp[90792]: SECURITY VIOLATION - scripts are being executed but script_security not enabled.
Apr 15 18:15:14 hmdg-db1 Keepalived_vrrp[90792]: Sync group ORACLE_HA_GROUP has only 1 virtual router(s) - removing
Apr 15 18:15:14 hmdg-db1 Keepalived_vrrp[90792]: Using LinkWatch kernel netlink reflector...
Apr 15 18:15:14 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Instance(Oracle_HA_1) Entering BACKUP STATE
Apr 15 18:15:14 hmdg-db1 Keepalived_vrrp[90792]: VRRP sockpool: [ifindex(3), proto(112), unicast(0), fd(10,11)]
Apr 15 18:15:14 hmdg-db1 Keepalived_vrrp[90792]: pid 90794 exited with status 1
Apr 15 18:15:14 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Script(change_monitor_status) succeeded
Apr 15 18:15:34 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Script(monitor_oracle_status) succeeded
Apr 15 18:15:34 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Instance(Oracle_HA_1) Changing effective priority from 100 to 120
  • 停止備服務(wù)器的keepalived服務(wù)

##系統(tǒng)日志
Apr 15 18:16:24 hmdg-db2 Keepalived_vrrp[83304]: VRRP_Instance(Oracle_HA_1) Entering BACKUP STATE
Apr 15 18:16:24 hmdg-db2 Keepalived_vrrp[83304]: VRRP sockpool: [ifindex(3), proto(112), unicast(0), fd(10,11)]
Apr 15 18:16:24 hmdg-db2 Keepalived_vrrp[83304]: VRRP_Script(change_monitor_status) succeeded
Apr 15 18:16:25 hmdg-db2 Keepalived_vrrp[83304]: VRRP_Script(monitor_oracle_status) succeeded
Apr 15 18:16:26 hmdg-db2 Keepalived_vrrp[83304]: VRRP_Instance(Oracle_HA_1) Changing effective priority from 90 to 110



##notify日志
-------------------------------------------------------------------------------
Apr  15 18:16:24 Sun hmdg-db2 [keepalived_notify]: Transition to STOP STATE
Apr  15 18:16:24 Sun hmdg-db2 [keepalived_notify]: removing the VIP on eth2 for 172.16.10.130,172.16.10.131
 
-------------------------------------------------------------------------------
Apr  15 18:16:24 Sun hmdg-db2 [keepalived_notify]: Transition to BACKUP STATE
Apr  15 18:16:24 Sun hmdg-db2 [keepalived_notify]: removing the VIP on eth2 for 172.16.10.130,172.16.10.131
Apr  15 18:16:24 Sun hmdg-db2 [keepalived_notify]: Database Switchover To BACKUP
Apr  15 18:16:24 Sun hmdg-db2 [keepalived_notify]: Database instance state is mounted
Apr  15 18:16:25 Sun hmdg-db2 [keepalived_notify]: Backup current controlfile.
 
SQL> alter database backup controlfile to '/backup/oracle/control/control_20181504181624';
 
 
Database altered.
 
Apr  15 18:16:25 Sun hmdg-db2 [keepalived_notify]: Shutdown database instance, please wait...
Database closed.
Database dismounted.
ORACLE instance shut down.
Apr  15 18:16:34 Sun hmdg-db2 [keepalived_notify]: Database instance shutdown successfully.
 
Apr  15 18:16:34 Sun hmdg-db2 [keepalived_notify]: umount sharedisk
 
Apr  15 18:16:34 Sun hmdg-db2 [keepalived_notify]: umount /oradata success.
Apr  15 18:16:34 Sun hmdg-db2 [keepalived_notify]: stopping listener...
Apr  15 18:16:38 Sun hmdg-db2 [keepalived_notify]: The listener stop successfully



##服務(wù)狀態(tài)
[root@hmdg-db2 scripts]# ps -ef | grep ora_
root      84619  31390  0 18:18 pts/2    00:00:00 grep ora_
[root@hmdg-db2 scripts]# df -Th
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/sda3      ext4    50G   18G   30G  37% /
tmpfs          tmpfs  3.9G     0  3.9G   0% /dev/shm
/dev/sda1      ext4   190M   40M  141M  22% /boot
[root@hmdg-db2 scripts]# ip addr show dev eth2
3: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:dd:d1:7f brd ff:ff:ff:ff:ff:ff
    inet 172.16.10.26/24 brd 172.16.10.255 scope global eth2
    inet6 fe80::20c:29ff:fedd:d17f/64 scope link
       valid_lft forever preferred_lft forever


  • 檢查DB1是否轉(zhuǎn)換為MASTER并接管服務(wù)資源

##DB1的系統(tǒng)日志
Apr 15 18:15:14 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Script(change_monitor_status) succeeded
Apr 15 18:15:34 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Script(monitor_oracle_status) succeeded
Apr 15 18:15:34 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Instance(Oracle_HA_1) Changing effective priority from 100 to 120
Apr 15 18:16:23 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Instance(Oracle_HA_1) Transition to MASTER STATE
Apr 15 18:16:25 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Instance(Oracle_HA_1) Entering MASTER STATE
Apr 15 18:16:25 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Instance(Oracle_HA_1) setting protocol VIPs.
Apr 15 18:16:25 hmdg-db1 Keepalived_vrrp[90792]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:16:25 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Instance(Oracle_HA_1) Sending/queueing gratuitous ARPs on eth2 for 172.16.10.130
Apr 15 18:16:25 hmdg-db1 Keepalived_vrrp[90792]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:16:25 hmdg-db1 Keepalived_healthcheckers[90790]: Netlink reflector reports IP 172.16.10.130 added
Apr 15 18:16:25 hmdg-db1 Keepalived_healthcheckers[90790]: Netlink reflector reports IP 172.16.10.131 added
Apr 15 18:16:25 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Instance(Oracle_HA_1) Sending/queueing gratuitous ARPs on eth2 for 172.16.10.131
Apr 15 18:16:25 hmdg-db1 Keepalived_vrrp[90792]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:16:25 hmdg-db1 Keepalived_vrrp[90792]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:16:25 hmdg-db1 Keepalived_vrrp[90792]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:16:25 hmdg-db1 Keepalived_vrrp[90792]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:16:25 hmdg-db1 Keepalived_vrrp[90792]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:16:25 hmdg-db1 Keepalived_vrrp[90792]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:16:25 hmdg-db1 Keepalived_vrrp[90792]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:16:25 hmdg-db1 Keepalived_vrrp[90792]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:16:30 hmdg-db1 Keepalived_vrrp[90792]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:16:30 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Instance(Oracle_HA_1) Sending/queueing gratuitous ARPs on eth2 for 172.16.10.130
Apr 15 18:16:30 hmdg-db1 Keepalived_vrrp[90792]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:16:30 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Instance(Oracle_HA_1) Sending/queueing gratuitous ARPs on eth2 for 172.16.10.131
Apr 15 18:16:30 hmdg-db1 Keepalived_vrrp[90792]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:16:30 hmdg-db1 Keepalived_vrrp[90792]: Sending gratuitous ARP on eth2 for 172.16.10.131



##DB1的notify腳本日志
-------------------------------------------------------------------------------
Apr  15 18:16:25 Sun hmdg-db1 [keepalived_notify]: Transition to MASTER STATE
Apr  15 18:16:25 Sun hmdg-db1 [keepalived_notify]: Setup the VIP on eth2 172.16.10.130,172.16.10.131
Apr  15 18:16:25 Sun hmdg-db1 [keepalived_notify]: Database Switchover To MASTER
Apr  15 18:16:25 Sun hmdg-db1 [keepalived_notify]: Check remote node sharedisk mounted.
Apr  15 18:16:26 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [1]...
Apr  15 18:16:27 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [2]...
Apr  15 18:16:28 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [3]...
Apr  15 18:16:29 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [4]...
Apr  15 18:16:30 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [5]...
Apr  15 18:16:31 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [6]...
Apr  15 18:16:32 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [7]...
Apr  15 18:16:34 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [8]...
Apr  15 18:16:35 Sun hmdg-db1 [keepalived_notify]: /dev/sdb1 check passed.
Apr  15 18:16:35 Sun hmdg-db1 [keepalived_notify]: mount /dev/sdb1 on /oradata
Apr  15 18:16:35 Sun hmdg-db1 [keepalived_notify]: restore controlfile 1
ORACLE instance started.
 
Total System Global Area 1603411968 bytes
Fixed Size                 2213776 bytes
Variable Size          1056966768 bytes
Database Buffers     536870912 bytes
Redo Buffers             7360512 bytes
 
Recovery Manager: Release 11.2.0.1.0 - Production on Sun Apr 15 18:16:38 2018
 
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
 
connected to target database: HMODB (not mounted)
using target database control file instead of recovery catalog
 
RMAN>
Starting restore at 15-APR-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=572 device type=DISK
 
channel ORA_DISK_1: copied control file copy
output file name=/oradata/HMODB/control01.ctl
output file name=/u01/app/oracle/flash_recovery_area/HMODB/control02.ctl
output file name=/home/oracle/rman/HMODB/control03.ctl
Finished restore at 15-APR-18
 
RMAN>
 
Recovery Manager complete.
Apr  15 18:16:40 Sun hmdg-db1 [keepalived_notify]: alter database to mount
 
Database altered.
 
Apr  15 18:16:44 Sun hmdg-db1 [keepalived_notify]: alter database to open
 
Database altered.
 
Apr  15 18:16:50 Sun hmdg-db1 [keepalived_notify]: Database opened.
Apr  15 18:16:50 Sun hmdg-db1 [keepalived_notify]: Startup listener
Apr  15 18:16:50 Sun hmdg-db1 [keepalived_notify]: starting listener...
Apr  15 18:16:50 Sun hmdg-db1 [keepalived_notify]: The listener startup successfully


##服務(wù)狀態(tài)
[root@hmdg-db1 scripts]# ps -ef | grep ora_
oracle    91765      1  0 18:16 ?        00:00:00 ora_pmon_HMODB
oracle    91767      1  0 18:16 ?        00:00:00 ora_vktm_HMODB
oracle    91771      1  0 18:16 ?        00:00:00 ora_gen0_HMODB
oracle    91773      1  0 18:16 ?        00:00:00 ora_diag_HMODB
oracle    91775      1  0 18:16 ?        00:00:00 ora_dbrm_HMODB
oracle    91777      1  0 18:16 ?        00:00:00 ora_psp0_HMODB
oracle    91779      1  0 18:16 ?        00:00:00 ora_dia0_HMODB
oracle    91781      1  0 18:16 ?        00:00:00 ora_mman_HMODB
oracle    91783      1  0 18:16 ?        00:00:00 ora_dbw0_HMODB
oracle    91785      1  0 18:16 ?        00:00:00 ora_lgwr_HMODB
oracle    91787      1  0 18:16 ?        00:00:00 ora_ckpt_HMODB
oracle    91789      1  0 18:16 ?        00:00:00 ora_smon_HMODB
oracle    91791      1  0 18:16 ?        00:00:00 ora_reco_HMODB
oracle    91793      1  0 18:16 ?        00:00:00 ora_mmon_HMODB
oracle    91795      1  0 18:16 ?        00:00:00 ora_mmnl_HMODB
oracle    91797      1  0 18:16 ?        00:00:00 ora_d000_HMODB
oracle    91799      1  0 18:16 ?        00:00:00 ora_s000_HMODB
oracle    91965      1  0 18:16 ?        00:00:00 ora_arc0_HMODB
oracle    91967      1  0 18:16 ?        00:00:00 ora_arc1_HMODB
oracle    91969      1  0 18:16 ?        00:00:00 ora_arc2_HMODB
oracle    91971      1  0 18:16 ?        00:00:00 ora_arc3_HMODB
oracle    91999      1  0 18:16 ?        00:00:00 ora_qmnc_HMODB
oracle    92090      1  0 18:16 ?        00:00:00 ora_cjq0_HMODB
oracle    92105      1  0 18:16 ?        00:00:00 ora_vkrm_HMODB
oracle    92181      1  0 18:16 ?        00:00:00 ora_q000_HMODB
oracle    92183      1  0 18:16 ?        00:00:00 ora_q001_HMODB
oracle    93817      1  0 18:20 ?        00:00:00 ora_j000_HMODB
oracle    93819      1  0 18:20 ?        00:00:00 ora_j001_HMODB
root      94030   2451  0 18:20 pts/0    00:00:00 grep ora_
[root@hmdg-db1 scripts]# df -Th
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/sda3      ext4    50G   19G   29G  40% /
tmpfs          tmpfs  3.9G  909M  3.0G  24% /dev/shm
/dev/sda1      ext4   190M   40M  141M  22% /boot
/dev/sdb1      ext4    30G  6.0G   22G  22% /oradata
[root@hmdg-db1 scripts]# ip addr show dev eth2
3: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:59:d5:91 brd ff:ff:ff:ff:ff:ff
    inet 172.16.10.25/24 brd 172.16.10.255 scope global eth2
    inet 172.16.10.130/24 scope global secondary eth2
    inet 172.16.10.131/24 scope global secondary eth2
    inet6 fe80::20c:29ff:fe59:d591/64 scope link
       valid_lft forever preferred_lft forever


測試當(dāng)主服務(wù)器Oracle服務(wù)關(guān)閉時

1、手動關(guān)閉DB1的數(shù)據(jù)庫實例

[oracle@hmdg-db1 ~]$ export ORACLE_SID=HMODB
[oracle@hmdg-db1 ~]$ sqlplus / as sysdba
 
SQL*Plus: Release 11.2.0.1.0 Production on Sun Apr 15 18:21:52 2018
 
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
 
 
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
 
SQL> SELECT OPEN_MODE,NAME,DATABASE_ROLE FROM V$DATABASE;
 
OPEN_MODE      NAME      DATABASE_ROLE
-------------------- --------- ----------------
READ WRITE       HMODB     PRIMARY
 
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

2、查看keepalived日志

##
Apr 15 18:23:34 hmdg-db1 Keepalived_vrrp[90792]: pid 96098 exited with status 2
Apr 15 18:23:48 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Instance(Oracle_HA_1) Received advert with higher priority 110, ours 100
Apr 15 18:23:48 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Instance(Oracle_HA_1) Entering BACKUP STATE
Apr 15 18:23:48 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Instance(Oracle_HA_1) removing protocol VIPs.
Apr 15 18:23:48 hmdg-db1 Keepalived_healthcheckers[90790]: Netlink reflector reports IP 172.16.10.130 removed
Apr 15 18:23:48 hmdg-db1 Keepalived_healthcheckers[90790]: Netlink reflector reports IP 172.16.10.131 removed
Apr 15 18:23:54 hmdg-db1 Keepalived_vrrp[90792]: pid 96486 exited with status 2
Apr 15 18:24:14 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Script(monitor_oracle_status) succeeded
Apr 15 18:24:15 hmdg-db1 Keepalived_vrrp[90792]: VRRP_Instance(Oracle_HA_1) Changing effective priority from 100 to 120


-------------------------------------------------------------------------------
Apr  15 18:23:48 Sun hmdg-db1 [keepalived_notify]: Transition to BACKUP STATE
Apr  15 18:23:48 Sun hmdg-db1 [keepalived_notify]: removing the VIP on eth2 for 172.16.10.130,172.16.10.131
Apr  15 18:23:48 Sun hmdg-db1 [keepalived_notify]: Database Switchover To BACKUP
Apr  15 18:23:49 Sun hmdg-db1 [keepalived_notify]: Database instance state is mounted
Apr  15 18:23:49 Sun hmdg-db1 [keepalived_notify]: Backup current controlfile.
 
SQL> alter database backup controlfile to '/backup/oracle/control/control_20181504182348';
 
 
Database altered.
 
Apr  15 18:23:49 Sun hmdg-db1 [keepalived_notify]: Shutdown database instance, please wait...
Database closed.
Database dismounted.
ORACLE instance shut down.
Apr  15 18:23:55 Sun hmdg-db1 [keepalived_notify]: Database instance shutdown successfully.
 
Apr  15 18:23:55 Sun hmdg-db1 [keepalived_notify]: umount sharedisk
 
Apr  15 18:23:55 Sun hmdg-db1 [keepalived_notify]: umount /oradata success.
Apr  15 18:23:55 Sun hmdg-db1 [keepalived_notify]: stopping listener...
Apr  15 18:23:56 Sun hmdg-db1 [keepalived_notify]: The listener stop successfully



[root@hmdg-db1 scripts]# ps -ef | grep ora_
root      97520   2451  0 18:26 pts/0    00:00:00 grep ora_
[root@hmdg-db1 scripts]# df -Th
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/sda3      ext4    50G   19G   29G  40% /
tmpfs          tmpfs  3.9G     0  3.9G   0% /dev/shm
/dev/sda1      ext4   190M   40M  141M  22% /boot
[root@hmdg-db1 scripts]# ip addr show dev eth2
3: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:59:d5:91 brd ff:ff:ff:ff:ff:ff
    inet 172.16.10.25/24 brd 172.16.10.255 scope global eth2
    inet6 fe80::20c:29ff:fe59:d591/64 scope link
       valid_lft forever preferred_lft forever


3、查看DB2是否轉(zhuǎn)換為MASTER并接管服務(wù)

##系統(tǒng)日志
Apr 15 18:23:49 hmdg-db2 Keepalived_vrrp[88134]: VRRP_Instance(Oracle_HA_1) forcing a new MASTER election
Apr 15 18:23:51 hmdg-db2 Keepalived_vrrp[88134]: VRRP_Instance(Oracle_HA_1) Transition to MASTER STATE
Apr 15 18:23:53 hmdg-db2 Keepalived_vrrp[88134]: VRRP_Instance(Oracle_HA_1) Entering MASTER STATE
Apr 15 18:23:53 hmdg-db2 Keepalived_vrrp[88134]: VRRP_Instance(Oracle_HA_1) setting protocol VIPs.
Apr 15 18:23:53 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:23:53 hmdg-db2 Keepalived_vrrp[88134]: VRRP_Instance(Oracle_HA_1) Sending/queueing gratuitous ARPs on eth2 for 172.16.10.130
Apr 15 18:23:53 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:23:53 hmdg-db2 Keepalived_healthcheckers[88133]: Netlink reflector reports IP 172.16.10.130 added
Apr 15 18:23:53 hmdg-db2 Keepalived_healthcheckers[88133]: Netlink reflector reports IP 172.16.10.131 added
Apr 15 18:23:53 hmdg-db2 Keepalived_vrrp[88134]: VRRP_Instance(Oracle_HA_1) Sending/queueing gratuitous ARPs on eth2 for 172.16.10.131
Apr 15 18:23:53 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:23:53 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:23:53 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:23:53 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:23:53 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:23:53 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:23:53 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:23:53 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:23:57 hmdg-db2 kernel: EXT4-fs (sdb1): warning: maximal mount count reached, running e2fsck is recommended
Apr 15 18:23:57 hmdg-db2 kernel: EXT4-fs (sdb1): mounted filesystem with ordered data mode. Opts:
Apr 15 18:23:58 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:23:58 hmdg-db2 Keepalived_vrrp[88134]: VRRP_Instance(Oracle_HA_1) Sending/queueing gratuitous ARPs on eth2 for 172.16.10.130
Apr 15 18:23:58 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:23:58 hmdg-db2 Keepalived_vrrp[88134]: VRRP_Instance(Oracle_HA_1) Sending/queueing gratuitous ARPs on eth2 for 172.16.10.131
Apr 15 18:23:58 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:23:58 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:23:58 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:23:58 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:23:58 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:23:58 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.131
Apr 15 18:23:58 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.130
Apr 15 18:23:58 hmdg-db2 Keepalived_vrrp[88134]: Sending gratuitous ARP on eth2 for 172.16.10.131


##notify腳本日志
-------------------------------------------------------------------------------
Apr  15 18:23:53 Sun hmdg-db2 [keepalived_notify]: Transition to MASTER STATE
Apr  15 18:23:53 Sun hmdg-db2 [keepalived_notify]: Setup the VIP on eth2 172.16.10.130,172.16.10.131
Apr  15 18:23:53 Sun hmdg-db2 [keepalived_notify]: Database Switchover To MASTER
Apr  15 18:23:53 Sun hmdg-db2 [keepalived_notify]: Check remote node sharedisk mounted.
Apr  15 18:23:53 Sun hmdg-db2 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [1]...
Apr  15 18:23:54 Sun hmdg-db2 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [2]...
Apr  15 18:23:56 Sun hmdg-db2 [keepalived_notify]: /dev/sdb1 is already mounted on remote node or busy. checking [3]...
Apr  15 18:23:57 Sun hmdg-db2 [keepalived_notify]: /dev/sdb1 check passed.
Apr  15 18:23:57 Sun hmdg-db2 [keepalived_notify]: mount /dev/sdb1 on /oradata
Apr  15 18:23:57 Sun hmdg-db2 [keepalived_notify]: restore controlfile 1
ORACLE instance started.
 
Total System Global Area 1603411968 bytes
Fixed Size                 2213776 bytes
Variable Size          1056966768 bytes
Database Buffers     536870912 bytes
Redo Buffers             7360512 bytes
 
Recovery Manager: Release 11.2.0.1.0 - Production on Sun Apr 15 18:23:58 2018
 
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
 
connected to target database: HMODB (not mounted)
using target database control file instead of recovery catalog
 
RMAN>
Starting restore at 15-APR-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=572 device type=DISK
 
channel ORA_DISK_1: copied control file copy
output file name=/oradata/HMODB/control01.ctl
output file name=/u01/app/oracle/flash_recovery_area/HMODB/control02.ctl
output file name=/home/oracle/rman/HMODB/control03.ctl
Finished restore at 15-APR-18
 
RMAN>
 
Recovery Manager complete.
Apr  15 18:23:59 Sun hmdg-db2 [keepalived_notify]: alter database to mount
 
Database altered.
 
Apr  15 18:24:04 Sun hmdg-db2 [keepalived_notify]: alter database to open
 
Database altered.
 
Apr  15 18:24:11 Sun hmdg-db2 [keepalived_notify]: Database opened.
Apr  15 18:24:11 Sun hmdg-db2 [keepalived_notify]: Startup listener
Apr  15 18:24:11 Sun hmdg-db2 [keepalived_notify]: listener already started.


##服務(wù)狀態(tài)檢查(Oracle進(jìn)程、磁盤、VIP狀態(tài))
[root@hmdg-db2 scripts]# ps -ef | grep ora_
oracle    88629      1  0 18:23 ?        00:00:00 ora_pmon_HMODB
oracle    88631      1  0 18:23 ?        00:00:00 ora_vktm_HMODB
oracle    88635      1  0 18:23 ?        00:00:00 ora_gen0_HMODB
oracle    88637      1  0 18:23 ?        00:00:00 ora_diag_HMODB
oracle    88639      1  0 18:23 ?        00:00:00 ora_dbrm_HMODB
oracle    88641      1  0 18:23 ?        00:00:00 ora_psp0_HMODB
oracle    88643      1  0 18:23 ?        00:00:00 ora_dia0_HMODB
oracle    88645      1  0 18:23 ?        00:00:00 ora_mman_HMODB
oracle    88647      1  0 18:23 ?        00:00:00 ora_dbw0_HMODB
oracle    88649      1  0 18:23 ?        00:00:00 ora_lgwr_HMODB
oracle    88651      1  0 18:23 ?        00:00:00 ora_ckpt_HMODB
oracle    88653      1  0 18:23 ?        00:00:00 ora_smon_HMODB
oracle    88655      1  0 18:23 ?        00:00:00 ora_reco_HMODB
oracle    88657      1  0 18:23 ?        00:00:00 ora_mmon_HMODB
oracle    88659      1  0 18:23 ?        00:00:00 ora_mmnl_HMODB
oracle    88661      1  0 18:23 ?        00:00:00 ora_d000_HMODB
oracle    88663      1  0 18:23 ?        00:00:00 ora_s000_HMODB
oracle    88828      1  0 18:24 ?        00:00:00 ora_arc0_HMODB
oracle    88843      1  0 18:24 ?        00:00:00 ora_arc1_HMODB
oracle    88845      1  0 18:24 ?        00:00:00 ora_arc2_HMODB
oracle    88847      1  0 18:24 ?        00:00:00 ora_arc3_HMODB
oracle    88944      1  0 18:24 ?        00:00:00 ora_qmnc_HMODB
oracle    89011      1  0 18:24 ?        00:00:00 ora_cjq0_HMODB
oracle    89026      1  0 18:24 ?        00:00:00 ora_vkrm_HMODB
oracle    89054      1  0 18:24 ?        00:00:00 ora_q000_HMODB
oracle    89056      1  0 18:24 ?        00:00:00 ora_q001_HMODB
root      90790  31390  0 18:27 pts/2    00:00:00 grep ora_
[root@hmdg-db2 scripts]# df -Th
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/sda3      ext4    50G   18G   30G  37% /
tmpfs          tmpfs  3.9G  909M  3.0G  24% /dev/shm
/dev/sda1      ext4   190M   40M  141M  22% /boot
/dev/sdb1      ext4    30G  6.0G   22G  22% /oradata
[root@hmdg-db2 scripts]# ip addr show dev eth2
3: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:dd:d1:7f brd ff:ff:ff:ff:ff:ff
    inet 172.16.10.26/24 brd 172.16.10.255 scope global eth2
    inet 172.16.10.130/24 scope global secondary eth2
    inet 172.16.10.131/24 scope global secondary eth2
    inet6 fe80::20c:29ff:fedd:d17f/64 scope link
       valid_lft forever preferred_lft forever


結(jié)尾

    本篇中主要的重點再在于測試部分。關(guān)于如何設(shè)計數(shù)據(jù)庫高可用集群方案可作為參考




向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI