ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 管理RAC

管理RAC

原创 Linux操作系统 作者:yuecaibo 时间:2012-03-06 22:34:26 0 删除 编辑


机器关闭之后启动电脑后启动crs资源:
1、重新开机之后,要检查能不能看到iscsi磁盘。
ll /dev/raw
service iscsi start
2、查看集群服务状态
crs_stat -t 查看资源状态。
3、资源状态,如果有online和offline的则。
]# /etc/init.d/init.crs stop 先将所有资源关闭,等待几分钟,因为后台资源关闭是要时间的!
4、启动集群服务
]# /etc/init.d/init.crs start  启动集群脚本
之后再查看状态,如果都online则可以,不过没有则只能重复启动。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

备份和恢复OCR和votdisk磁盘:

查看voting disk位置:
# crsctl query css votedisk

备份voting disk
dd if=voting_disk_name f=backup_file_name
还原voting disk
dd if=backup_file_name f=voting_disk_name

查看备份
$ocrconfig -showbackup
备份(要在root下运行)
/data/oracle/crs/bin/ocrconfig -export /data/backup/rac/ocrdisk.bak
还原 需要停掉所有的节点,Stop the Oracle Clusterware software on all of the nodes
/data/oracle/crs/bin/ocrconfig -import file_name
自动备份的还原# /data/oracle/crs/bin/ocrconfig -showbackup
# /data/oracle/crs/bin/ocrconfig -restore
/data/oracle/crs/cdata/db168crs/backup00.ocrhosta$cluvfy comp ocr -n all

clusterware常用命令:
$ORA_CRS_HOME/bin/crs_stat (查看各个资源的完整服务名称)
$ORA_CRS_HOME/bin/crs_stat -t (查看各个资源的状态)
$ORA_CRS_HOME/bin/crs_stat -p

UNKNOWN状态服务的解决1:
# /etc/init.d/init.crs stop
# /etc/init.d/init.crs start

UNKNOWN状态服务的解决1:
./crs_stop -f ora.rac1.vip
./crs_start -f ora.rac1.vip

查看服务状态:
./srvctl status asm -n rac1

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

ASM磁盘信息查看:
两个实例自己的归档、日志、跟踪、回滾文件。
SQL> col file_name for a50
SQL> select file_name,bytes/1024/1024 from dba_data_files;    --查看磁盘信息

FILE_NAME                                          BYTES/1024/1024
-------------------------------------------------- ---------------
+DGA/racdb/datafile/users.266.740157799                          5
+DGA/racdb/datafile/sysaux.261.740157799                       230
+DGA/racdb/datafile/undotbs1.272.740157799                      25
+DGA/racdb/datafile/system.260.740157799                       480
+DGA/racdb/datafile/undotbs2.262.740157889                      25

10g中提供了工具查看ASM盘
export ORACLE_SID=+ASM2
[oracle@stu12 ~]$ asmcmd
ASMCMD> ls
DGA/
ASMCMD> cd DGA
ASMCMD> ls
RACDB/
ASMCMD> cd RACDB
ASMCMD> ls
CONTROLFILE/
DATAFILE/
ONLINELOG/
PARAMETERFILE/
TEMPFILE/
spfileracdb.ora
ASMCMD> cd CONTROLFILE/
ASMCMD> ls
Current.270.740157855  --这两个是文件的数字化身,唯一的
Current.271.740157857
ASMCMD> pwd
+DGA/RACDB/CONTROLFILE
ASMCMD> ls
SYSAUX.261.740157799
SYSTEM.260.740157799
UNDOTBS1.272.740157799  --一个节点就会有一个undo文件
UNDOTBS2.262.740157889
USERS.266.740157799
ASMCMD> cd ONLINELOG/
ASMCMD> ls
group_1.268.740157859  --这里日志组有很多
group_1.269.740157859
group_2.264.740157865
group_2.265.740157863
group_3.259.740158235
group_3.267.740158235
group_4.257.740158237
group_4.258.740158237

 

查看当前日志组信息:
SQL> select GROUP#,THREAD#,SEQUENCE#,STATUS from v$log;

    GROUP#    THREAD#  SEQUENCE# STATUS
---------- ---------- ---------- ----------------
         1          1          2 INACTIVE
         2          1          3 CURRENT
         3          2          1 INACTIVE
         4          2          2 CURRENT

查看当前节点的信息,确定使用的哪组日志:
SQL> show parameter name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string
db_name                              string      racdb
db_unique_name                       string      racdb
global_names                         boolean     FALSE
instance_name                        string      racdb2
lock_name_space                      string
log_file_name_convert                string
service_names                        string      racdb

SQL> show parameter thread

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
parallel_threads_per_cpu             integer     2
thread                               integer     2

切换日志观察日志文件使用情况:
SQL> alter system switch logfile;

SQL> select GROUP#,THREAD#,SEQUENCE#,STATUS from v$log;

    GROUP#    THREAD#  SEQUENCE# STATUS
---------- ---------- ---------- ----------------
         1          1          2 INACTIVE
         2          1          3 CURRENT
         3          2          3 CURRENT
         4          2          2 ACTIVE

Elapsed: 00:00:00.06

ASM存放数据的位置:
[oracle@stu12 ~]$ ll /dev/raw  真正的数据存放在了raw[3-4]下了,但是如果组织的数据就不清楚了。
total 0
crw-r----- 1 root   oinstall 162, 1 Jan 12 11:20 raw1
crw-r--r-- 1 oracle oinstall 162, 2 Jan 12 11:20 raw2
crw-rw---- 1 oracle oinstall 162, 3 Jan 12 11:20 raw3
crw-rw---- 1 oracle oinstall 162, 4 Jan 12 11:20 raw4

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

ASM中创建表空间:
SQL> select name from v$tablespace;

NAME
------------------------------
SYSTEM
UNDOTBS1
SYSAUX
USERS
TEMP
UNDOTBS2

6 rows selected.

Elapsed: 00:00:00.03
SQL> create tablespace demo datafile '+dga' size 10m;

Tablespace created.

Elapsed: 00:00:01.71
SQL> select name from v$tablespace;

NAME
------------------------------
SYSTEM
UNDOTBS1
SYSAUX
USERS
TEMP
UNDOTBS2
DEMO

7 rows selected.

Elapsed: 00:00:00.02
SQL> create tablespace demo2;  --ASM会自动分配空间和指定位置

Tablespace created.

Elapsed: 00:00:09.89

SQL> select name from v$datafile;

NAME
------------------------------------------------------------------------------------------------------------------------
+DGA/racdb/datafile/system.260.740157799
+DGA/racdb/datafile/undotbs1.272.740157799
+DGA/racdb/datafile/sysaux.261.740157799
+DGA/racdb/datafile/users.266.740157799
+DGA/racdb/datafile/undotbs2.262.740157889
+DGA/racdb/datafile/demo.273.740229885
+DGA/racdb/datafile/demo2.274.740229897

7 rows selected.

Elapsed: 00:00:00.08


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
重大操作<结构变化(开归档或闪回)>要将两个节点都停掉,之后在一个节点做就可以.


将RAC数据库切换为归档模式:

SQL> select INSTANCE_NAME,STATUS from gv$instance;  --查看两个实例的状态

INSTANCE_NAME    STATUS
---------------- ------------
racdb2           OPEN
racdb1           OPEN

1.将两个数据库全部关闭
shutdown immediate

2.将节点1数据库启动到mount状态
startup mount
alter database archivelog;
alter database open;

3.将节点2上的数据库启动到opne模式下.之后检查两个节点状态都是归档模式了.

出现问题:切换日志之后两个节点的监听不能正常启动
[root@stu12 bin]# ./crs_stat -t
Name           Type           Target    State     Host       
------------------------------------------------------------
ora.racdb.db   application    ONLINE    ONLINE    stu10      
ora....acdb.cs application    ONLINE    ONLINE    stu12      
ora....db1.srv application    ONLINE    ONLINE    stu12      
ora....db2.srv application    ONLINE    ONLINE    stu10      
ora....b1.inst application    ONLINE    ONLINE    stu12      
ora....b2.inst application    ONLINE    ONLINE    stu10      
ora....SM2.asm application    ONLINE    ONLINE    stu10      
ora....10.lsnr application    OFFLINE   UNKNOWN   stu10       --UNKNOWN状态可能是监听未正常关闭的结果,出现这种状态的时候有可能在另外的节点看到的状态不是这个.因为两个节点之间的通信出现了问题
ora.stu10.gsd  application    ONLINE    ONLINE    stu10      
ora.stu10.ons  application    ONLINE    ONLINE    stu10      
ora.stu10.vip  application    ONLINE    ONLINE    stu10      
ora....SM1.asm application    ONLINE    ONLINE    stu12      
ora....12.lsnr application    OFFLINE   OFFLINE              
ora.stu12.gsd  application    ONLINE    ONLINE    stu12      
ora.stu12.ons  application    ONLINE    ONLINE    stu12

[root@stu12 bin]# ./crs_stop ora.stu10.LISTENER_STU10.lsnr -f
Attempting to stop `ora.stu10.LISTENER_STU10.lsnr` on member `stu10`
Stop of `ora.stu10.LISTENER_STU10.lsnr` on member `stu10` succeeded.
[root@stu12 bin]# ./crs_start ora.stu10.LISTENER_STU10.lsnr

Attempting to start `ora.stu10.LISTENER_STU10.lsnr` on member `stu10`
Start of `ora.stu10.LISTENER_STU10.lsnr` on member `stu10` succeeded.

[root@stu12 bin]# ./crs_stat -t
Name           Type           Target    State     Host       
------------------------------------------------------------
ora.racdb.db   application    ONLINE    ONLINE    stu10      
ora....acdb.cs application    ONLINE    ONLINE    stu12      
ora....db1.srv application    ONLINE    ONLINE    stu12      
ora....db2.srv application    ONLINE    ONLINE    stu10      
ora....b1.inst application    ONLINE    ONLINE    stu12      
ora....b2.inst application    ONLINE    ONLINE    stu10      
ora....SM2.asm application    ONLINE    ONLINE    stu10      
ora....10.lsnr application    ONLINE    ONLINE    stu10      
ora.stu10.gsd  application    ONLINE    ONLINE    stu10      
ora.stu10.ons  application    ONLINE    ONLINE    stu10      
ora.stu10.vip  application    ONLINE    ONLINE    stu10      
ora....SM1.asm application    ONLINE    ONLINE    stu12      
ora....12.lsnr application    OFFLINE   OFFLINE              
ora.stu12.gsd  application    ONLINE    ONLINE    stu12      
ora.stu12.ons  application    ONLINE    ONLINE    stu12      
ora.stu12.vip  application    ONLINE    ONLINE    stu12      

[root@stu12 bin]# ./crs_start ora.stu12.LISTENER_STU12.lsnr
Attempting to start `ora.stu12.LISTENER_STU12.lsnr` on member `stu12`
Start of `ora.stu12.LISTENER_STU12.lsnr` on member `stu12` succeeded.

[root@stu12 bin]# ./crs_stat -t
Name           Type           Target    State     Host       
------------------------------------------------------------
ora.racdb.db   application    ONLINE    ONLINE    stu10      
ora....acdb.cs application    ONLINE    ONLINE    stu12      
ora....db1.srv application    ONLINE    ONLINE    stu12      
ora....db2.srv application    ONLINE    ONLINE    stu10      
ora....b1.inst application    ONLINE    ONLINE    stu12      
ora....b2.inst application    ONLINE    ONLINE    stu10      
ora....SM2.asm application    ONLINE    ONLINE    stu10      
ora....10.lsnr application    ONLINE    ONLINE    stu10      
ora.stu10.gsd  application    ONLINE    ONLINE    stu10      
ora.stu10.ons  application    ONLINE    ONLINE    stu10      
ora.stu10.vip  application    ONLINE    ONLINE    stu10      
ora....SM1.asm application    ONLINE    ONLINE    stu12      
ora....12.lsnr application    ONLINE    ONLINE    stu12      
ora.stu12.gsd  application    ONLINE    ONLINE    stu12      
ora.stu12.ons  application    ONLINE    ONLINE    stu12      
ora.stu12.vip  application    ONLINE    ONLINE    stu12

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
测试故障转移:
只能转移select,监听要配DB舰艇

检查两个服务器端监听的状态:
现查看本地监听的状态.
lsnrctl status  --查看是否所有实例都在

监听配置的时候要有dbname:
golable database name=racdb
sid name=racdb1

[oracle@stu12 admin]$ lsnrctl

LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 12-JAN-2011 14:58:05

Copyright (c) 1991, 2005, Oracle.  All rights reserved.

Welcome to LSNRCTL, type "help" for information.

LSNRCTL> set current_listener LISTENER_STU12
Current Listener is LISTENER_STU12
LSNRCTL> stop
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=stu12-vip)(PORT=1521)))
The command completed successfully
LSNRCTL> start

service_name在集群环境中是写入到OCR中的!修改很麻烦的

准备一个环境--
sqlplus scott/tiger
create table t (i int);
创建一张表,插入10万行数据:
create table t (id int)
begin
 for i in 1.100000 loop
 insert into t values (i);
 end loop;
 commit;
end;
/

在客户端连接之后,到一个服务端查看会话连接的是哪个实例:
sqlplus /nolog
conn sys/oracle@racdb as sysdba  ---测试是否能连接
conn scott/tiger@racdb
desc gv$session 
SQL> select inst_id,sid,USERNAME,machine,FAILOVER_TYPE,FAILOVER_METHOD,FAILED_OVER from gv$session where username='SCOTT';  ---查看连接者的状态,连接到1号节点

   INST_ID        SID USERNAME                       MACHINE  FAILOVER_TYPE FAILOVER_M FAI
---------- ---------- ------------------------------ ---------------------------------------------------------------------------- ---------- ---
         1        128 SCOTT                          stu10 NONE          NONE       NO


进入1号节点:
sqlplus / as sysdba
键入shutdown abort并等待客户端发起查询.


客户端:
在客户端配置个网络:
cd  $ORACLE_HOME/network/admin
vim tnsname.ora
RACDB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = stu12-vip)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = stu10-vip)(PORT = 1521))
      (LOAD_BALANCE = yes)
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = racdb)
      (FAILOVER_MODE =
        (BACKUP = racdb)
        (TYPE = SELECT)
        (METHOD = BASIC) 
        (RETRIES = 180)
        (DELAY = 5)
      )
    )
  )

tnsping racdb 5  --如果不通,查看一下hosts文件是否有远程主机的IP描述,修改之后要重新进入一下oracle用户.

客户端发起连接:
conn scott/tiger@racdb

生成一个查询:
select * from t;
在发出查询之后,立即停止1号实例的数据库.

 

服务器端从查询:
这时候查询还能继续直至完成,查询gv$session中FAILED_OVER显示为YES.
SQL> select inst_id,sid,FAILOVER_TYPE,FAILOVER_METHOD,FAILED_OVER from gv$session where username='SCOTT';

   INST_ID        SID FAILOVER_TYPE FAILOVER_M FAI
---------- ---------- ------------- ---------- ---
         1        145 SELECT        BASIC      YES


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
负载均衡:(oracle的负载均衡是假的,是辅助作用,真正的还是要用F5)

客户端负载均衡:
tnsname.ora文件中这两项,客户端连接中
RACDB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = stu12-vip)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = stu10-vip)(PORT = 1521))
      (LOAD_BALANCE = yes)
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = racdb)
      (FAILOVER_MODE =
        (BACKUP = racdb)
        (TYPE = SELECT)
        (METHOD = BASIC)
        (RETRIES = 180)
        (DELAY = 5)
      )
    )
  )

 

服务器端负载均衡:
SQL> show parameter remote

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
remote_archive_enable                string      true
remote_dependencies_mode             string      TIMESTAMP
remote_listener                      string      LISTENERS_RACDB
remote_login_passwordfile            string      EXCLUSIVE
remote_os_authent                    boolean     FALSE
remote_os_roles                      boolean     FALSE

在tnsname.ora中是和选项:oracle在后台会监测数据库的负载,自动将会话分发到低负载的节点上.
LISTENERS_RACDB =
  (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = stu12-vip)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = stu10-vip)(PORT = 1521))
  )

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24756465/viewspace-717895/,如需转载,请注明出处,否则将追究法律责任。

下一篇: DG 搭建
请登录后发表评论 登录
全部评论

注册时间:2012-03-03

  • 博文量
    42
  • 访问量
    37726