ASMLib的用处:
Project: ASMLib Kernel Driver
ASMLib allows an Oracle Database using ASM more efficient and capable access to the disk
groups it is using.
ASMlib不是必须的,但是安装了可以增加ASM磁盘组管理的简便性。
ASMLib 令使用 ASM 的 Oracle 数据库更加高效,并能够访问它正在使用的磁盘组。
安装 Oracle ASMLib
检查本机的内核版本
[root@racdb1 ~]# uname -r
2.6.9-55.ELsmp
Migrating Raw Devices to ASMLib
1、安装Oracle ASMLib
下载地址:
[root@racdb1 asm]# rpm -ivh oracleasm-support-2.0.3-1.i386.rpm
[root@racdb1 asm]# rpm -ivh oracleasm-2.6.9-55.0.12.EL-2.0.3-1.i686.rpm
[root@racdb1 asm]# rpm -ivh oracleasmlib-2.0.2-1.i386.rpm
2、配置ASMLib
[root@racdb1 asm]# /etc/init.d/oracleasm configure
Default user to own the driver interface []: oracle
Default group to own the driver interface []: dba
Start Oracle ASM library driver on boot (y/n) [n]: y
Fix permissions of Oracle ASM disks on boot (y/n) [y]: y
Writing Oracle ASM library driver configuration: [ OK ]
Creating /dev/oracleasm mount point: [ OK ]
Loading module "oracleasm": Unable to load module "oracleasm"
[FAILED]
最后出现错误,检查
[root@racdb1 asm]# tail -100 /var/log/messages
[root@racdb1 asm]# rpm -qa | grep oracleasm
[root@racdb1 asm]# uname -rm
[root@racdb1 asm]# rpm -qa | grep kernel
发觉是安装的版本不对,开始以为满足kernel的大版本就可
[root@racdb1 asm]# rpm -e oracleasmlib-2.0.2-1
[root@racdb1 asm]# rpm -e oracleasm-2.6.9-55.0.12.EL-2.0.3-1
注:rpm若一定要删除,可以使用:#rpm -e XXX --nodeps
下载安装正确的版本:
[root@racdb1 asm]# rpm -Uvh oracleasm-2.6.9-55.EL-2.0.3-1.i686.rpm
[root@racdb1 asm]# rpm -Uvh oracleasmlib-2.0.2-1.i386.rpm
[root@racdb1 asm]# rpm -ivh oracleasm-2.6.9-55.ELsmp-2.0.3-1.i686.rpm
添加init文件使系统启动时自动加载ASMLib
[root@racdb1 rc3.d]# ll *oracleasm
lrwxrwxrwx 1 root root 19 Mar 1 12:26 S29oracleasm -> ../init.d/oracleasm
#cd /etc/rc3.d
#ln -s ../init.d/oracleasm K01oracleasm
重新启动系统,确认ASMLib已经可以自动加载
#lsmod |grep oracleasm
#dmesg |grep oracleasm
就我的理解,如果是单个磁盘,或容量比较小的,直接只用如 /dev/sda, /dev/sdb就可,
如果容量比较大,才需要分区(比如外置磁盘柜的lun),使用如/dev/sda1, /dev/sda2
修改磁盘所有者:
[root@racdb1 dev]# chown oracle /dev/sdd*
[root@racdb1 dev]# chmod 660 /dev/sdd*
[root@racdb1 dev]# ll /dev/sdd*
如果之前ASM已经使用过该磁盘,可以清除掉head信息:
[root@racdb1 ~]# dd if=/dev/zero of=/dev/sdc bs=1M count=1024
[root@racdb1 ~]# dd if=/dev/zero of=/dev/sdd bs=1M count=2024
如果用fdisk之类工具对磁盘重新分区,让系统重新扫描磁盘分区:
[root@racdb1 raw]# partprobe
创建ASM磁盘:
[root@racdb1 ~]# /etc/init.d/oracleasm createdisk VOL1 /dev/sdc1
Marking disk "/dev/sdc1" as an ASM disk: [ OK ]
[root@racdb1 ~]# /etc/init.d/oracleasm createdisk VOL2 /dev/sdc2
Marking disk "/dev/sdc2" as an ASM disk: [ OK ]
[root@racdb1 ~]# /etc/init.d/oracleasm createdisk VOL3 /dev/sdd1
Marking disk "/dev/sdd1" as an ASM disk: [ OK ]
[root@racdb1 ~]# /etc/init.d/oracleasm createdisk VOL4 /dev/sdd2
Marking disk "/dev/sdd2" as an ASM disk: [ OK ]
[root@racdb1 ~]# /etc/init.d/oracleasm listdisks
VOL1
VOL2
VOL3
VOL4
如果要删除ASM磁盘通过以下命令
#/etc/init.d/oracleasm deletedisk VOL4
On all other RAC nodes, you just need to notify the system about the new ASM disks:
如果有多节点的rac
[root@racdb1 ~]# /etc/init.d/oracleasm scandisks
Scanning system for ASM disks: [ OK ]
[root@racdb1 disks]# /etc/init.d/oracleasm status
Checking if ASM is loaded: [ OK ]
Checking if /dev/oracleasm is mounted: [ OK ]
注意mount在 /dev/oracleasm
安装oracle, 打补丁
运行netca
运行dbca
选择 asm
按提示运行, 安装crs:
[root@racdb1 ~]# /u01/oracle/product/db_1/bin/localconfig add
创建磁盘组
参考:
磁盘组名称
- 输入磁盘组名称,如 DATA1。
冗余
- High 镜像数据两次(三份数据)。
- Normal 镜像数据一次(两份数据)。
- External 不镜像 ASM 中的数据。如果外部 RAID 阵列提供冗余,则通常使用此选项。
选择成员磁盘
- 您必须手动指示 ASM 到什么地方查找 ASMLib 磁盘,因此,单击 Change Disk Discovery Path
- 弹出一个窗口,提示输入磁盘发现路径。如下所示将磁盘发现路径更改为"/dev/sd*". “ORCL:*”。
在这里,我只有输入"/dev/oracleasm/disks/VOL*"才能找到磁盘
- 单击 OK 继续。
您将返回到 Select Member Disks 窗口。您的所有 ASMLib 磁盘现在应显示在此窗口中。
单击该行开头的框,选择加入磁盘组的磁盘。完成后单击 OK。
管理ASM Disk Groups
登录及启动关闭:
$ ORACLE_SID=+ASM; export ORACLE_SID
$ sqlplus "/ as sysdba"
SQL> startup
SQL> shutdown immediate;
解决错误:
ORA-15032: not all alterations performed
ORA-15063: ASM discovered an insufficient number of disks for diskgroup "DATA1"
清除已经移除物理磁盘的DISKGROUP
[oracle@racdb1 dbs]$ strings spfile+ASM.ora | more
SQL> alter system set asm_diskgroups=DGDATA scope=spfile;
SQL> alter system set asm_diskgroups=DGDATA scope=spfile sid='+ASM';
两个很有用的检查disk group信息的SQL,下面的设置会反复用到:
SQL> col state format a10
SQL> col name format a15
SQL> col failgroup format a20
SQL> set line 200
SQL> select STATE,REDUNDANCY,TOTAL_MB,FREE_MB,NAME,FAILGROUP from v$asm_disk;
SQL> select GROUP_NUMBER,NAME,STATE,TYPE,TOTAL_MB,FREE_MB,UNBALANCED from v$asm_diskgroup;
-- 创建新的diskgroup
SQL> create diskgroup dgtest normal redundancy
2 failgroup dgtest_0001 disk '/dev/oracleasm/disks/VOL5' name dgtest_0001
3 failgroup dgtest_0002 disk '/dev/oracleasm/disks/VOL6' name dgtest_0002;
-- 删除diskgroup
SQL> drop diskgroup dgtest including contents;
-- 为diskgroup增加disk
SQL> alter diskgroup dgdata add disk '/dev/oracleasm/disks/VOL5' name
dgdata_0004,'/dev/oracleasm/disks/VOL6' name dgdata_0005;
-- 从diskgroup删除disk
SQL> alter diskgroup dgdata drop disk DGDATA_0004;
-- 取消删除disk的命令,只能在上述命令没执行完成的时候有效
The UNDROP DISKS clause of the ALTER DISKGROUP statement allows pending disk drops to be
undone. It will not revert drops that have completed, or disk drops associated with the
dropping of a disk group.
ALTER DISKGROUP disk_group_1 UNDROP DISKS;
SQL> show parameter asm_power_limit
这个参数 ASM_POWER_LIMIT
参数控制 ASM 后台进程 ARBx 的数量。ARBx 进程用来进行 ASM 磁盘数据重新分布打散。ASM_POWER_LIMIT 取值 从
0 到 11(据说从 10gR2 开始可以设置为 0 ). 当新添加磁盘或者删除磁盘后,ASM 会启动 ARBx 进行 IO
分散操作,这是个非常消耗资源的动作,所以一定要选择系统空闲的时候进行。
SQL> alter diskgroup dgdata rebalance power 5;
Disk
groups can be rebalanced manually using the REBALANCE clause of the
ALTER DISKGROUP statement. If the POWER clause is omitted the
ASM_POWER_LIMIT parameter value is used. Rebalancing is only needed
when the speed of the automatic rebalancing is not appropriate.
其它一些手动mount命令
ALTER DISKGROUP ALL DISMOUNT;
ALTER DISKGROUP ALL MOUNT;
ALTER DISKGROUP dgdata DISMOUNT;
ALTER DISKGROUP dgdata MOUNT;
数据文件的管理
Aliases allow you to reference ASM files using user-friendly names, rather than the fully
qualified ASM filenames.
-- Create an alias using the fully qualified filename.
ALTER DISKGROUP disk_group_1 ADD ALIAS '+disk_group_1/my_dir/my_file.dbf'
FOR '+disk_group_1/mydb/datafile/my_ts.342.3';
-- Create an alias using the numeric form filename.
ALTER DISKGROUP disk_group_1 ADD ALIAS '+disk_group_1/my_dir/my_file.dbf'
FOR '+disk_group_1.342.3';
-- Rename an alias.
ALTER DISKGROUP disk_group_1 RENAME ALIAS '+disk_group_1/my_dir/my_file.dbf'
TO '+disk_group_1/my_dir/my_file2.dbf';
-- Delete an alias.
ALTER DISKGROUP disk_group_1 DELETE ALIAS '+disk_group_1/my_dir/my_file.dbf';
-- Drop file using an alias.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1/my_dir/my_file.dbf';
-- Drop file using a numeric form filename.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1.342.3';
-- Drop file using a fully qualified filename.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1/mydb/datafile/my_ts.342.3';
-- create datafile
SQL> create tablespace users2 datafile '+TESTDB_DATA1' size 100m;