Dec 1

[原]编写红旗HA 4.1启动、关闭和监控脚本 晴

linuxing , 11:02 , 网络服务 » HA , 评论(0) , 引用(0) , 阅读(32884) , Via 本站原创 | |
  上面用模板的方式介绍了如何安装红旗HA 4.1,但里面没有详细的介绍启动、关闭脚本以及监控脚本的编写方式,今天再来看看。
1、准备
  在编写脚本前,我们需要了解清楚脚本的编写位置以及它实际运行位置的不同:
  假设我们使用配置工具生成的clp.conf文件存放在/rfha目录中,而HA软件默认是安装在/opt/redflag/hacluster目录中,就出现了这样的对应关系:
引用

/rfha/scripts/oracle   ==>  /opt/redflag/hacluster/scripts/oracle

   基于这样的关系,HA自身引用的start.sh和stop.sh的路径是已经嵌入到HA中的,所以可以不用调整;但start.sh和stop.sh中使用的命令,如果原来是放在/rfha/scipts下的话,这必须在start.sh和stop.sh中使用绝对路径,指向/opt/redflag/hacluster/scripts目录中。
  理论的说明不容易理解,我们从下面的实例讲解吧。
※必须记住的一点是,所有引用的命令,除非有PATH指定,否则都应该放在和clp.conf文件的同一个上层目录中,也就是/rfha/scripts下。否则导入配置后,另一台机器就找不到路径了。

2、编写启动和关闭脚本
1)先是编写HA的启动和关闭脚本:
◎路径:/rfha/scripts/oracle/oracleexec/
◎start.sh:

echo "NORMAL1"
                if [ "$CLP_SERVER" = "HOME" ]
                then
                        echo "NORMAL2"
                else
                        echo "ON_OTHER1"
                fi
su - oracle -c "/opt/redflag/hacluster/scripts/oracle/oracleexec/dbstart"
su - oracle -c "lsnrctl start;agentctl start"
        else
                echo "ERROR_DISK from START"

以及

echo "FAILOVER2"
                else
                        echo "ON_OTHER2"
                fi
su - oracle -c "/opt/redflag/hacluster/scripts/oracle/oracleexec/dbstart"
su - oracle -c "lsnrctl start;agentctl start"
        else
                echo "ERROR_DISK from FAILOVER"


◎stop.sh:

echo "NORMAL2"
                else
                        echo "ON_OTHER1"
                fi
su - oracle -c "lsnrctl stop;agentctl stop"
su - oracle -c "/opt/redflag/hacluster/scripts/oracle/oracleexec/dbshut"
        else
                echo "ERROR_DISK from START"

以及

echo "FAILOVER2"
                else
                        echo "ON_OTHER2"
                fi
su - oracle -c "lsnrctl stop;agentctl stop"
su - oracle -c "/opt/redflag/hacluster/scripts/oracle/oracleexec/dbshut"
        else
                echo "ERROR_DISK from FAILOVER"

※注意启动和关闭命令的绝对路径以及命令在start.sh、stop.sh脚本中的位置
2)引用的Oracle启动和关闭命令
◎路径/rfha/scripts/oracle/oracleexec/
◎dbstart:
[root@db01 oracleexec]# pwd
/rfha/scripts/oracle/oracleexec
[root@db01 oracleexec]# cat dbstart
sqlplus /nolog <<EOF
conn / as sysdba
startup
EOF

◎dbshut:

[root@db01 oracleexec]# pwd
/rfha/scripts/oracle/oracleexec
[root@db01 oracleexec]# cat dbshut
sqlplus /nolog <<EOF
conn / as sysdba
shutdown immediate
EOF

3)留意dbstart和dbshut绝对路径的位置。
  因为配置只是在其中一台机器db01上配置的,db02上并没有/rfha目录。
  所以,在我们导入配置的时候,dbstart和dbshut的路径就会改变了。
4)导入到HA配置文件中
点击在新窗口中浏览此图片
点击在新窗口中浏览此图片
点击在新窗口中浏览此图片

3、编写监控脚本
◎路径/rfha/scripts/oracle/oraclemon/
◎start.sh:

[root@db01 oraclemon]# cat start.sh
#! /bin/sh
#***************************************
#*              start.sh               *
#***************************************

#set -n
declare -a PROCS
PROCS[0]="ora_pmon"
PROCS[1]="ora_dbw"
PROCS[2]="ora_lgwr"
PROCS[3]="ora_ckpt"
PROCS[4]="ora_smon"
PROCS[5]="ora_reco"

#PROCS[2]="XXXX" #u can add new process
while true; do
                echo $PROCS
                for proc in "${PROCS[@]}"
                do
                        echo $proc
                        running=`ps -ef |grep $proc | grep -v grep`
                        if [ "x" = "x$running" ]; then
                                echo "$proc is not present now!"
                                exit 2  #break while loop
                        fi
                done
                sleep 5  #sleep for next while loop
done
Tags: , ,
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]