合 Oracle ASMLIB 系列-- oracleasm
简介
创建ASM磁盘请参考:https://www.dbaup.com/zaioraclezhongchuangjianasmcipandenzhongfangfa.html
说明:RHEL6、 RHEL7、CentOS6、CentOS7 都可以使用asmlib,只不过需要安装kmod-oracleasm包。 RHEL5不需要安装 kmod-oracleasm包 。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | ---------------------------- oracleasm常用命令 asmlib oracleasm日志: tail -f /var/log/oracleasm /usr/sbin/oracleasm configure -i /usr/sbin/oracleasm createdisk DISK1 /dev/sdb1 /etc/init.d/oracleasm scandisks /etc/init.d/oracleasm listdisks /etc/init.d/oracleasm enable /etc/init.d/oracleasm restart /etc/init.d/oracleasm status /etc/init.d/oracleasm init /usr/sbin/oracleasm enable /usr/sbin/oracleasm restart /usr/sbin/oracleasm createdisk DISKNAME devicename /usr/sbin/oracleasm deletedisk DISKNAME /usr/sbin/oracleasm querydisk {DISKNAME | devicename} /usr/sbin/oracleasm listdisks /usr/sbin/oracleasm scandisks ls -l /dev/oracleasm/disks --asmlib配置文件 cat /etc/sysconfig/oracleasm oracleasm configure oracleasm日志: tail -f /var/log/oracleasm 安装: ## 先安装kmod-oracleasm,再安装oracleasmlib和oracleasm-support --------------- rhel6.5安装asmlib:https:///search yum install -y kmod-oracleasm # # wget 下载:https:///linux/downloads/linux-asmlib-rhel6-downloads.html wget wget rpm -ivh *.rpm oracleasm configure -i # grid,asmadmin,y,y oracleasm configure -d oracleasm configure -e oracleasm init oracleasm status fdisk -l | grep dev oracleasm createdisk ocr01 /dev/vdb1 oracleasm listdisks oracleasm renamedisk -f /dev/sdf1 asmdisk3 --------------- rhel7安装asmlib:https:///search yum install -y kmod-oracleasm # # wget 下载:https:///linux/downloads/linux-asmlib-rhel7-downloads.html wget wget rpm -ivh *.rpm systemctl enable oracleasm.service oracleasm configure -i # grid,asmadmin,y,y oracleasm configure -d oracleasm configure -e oracleasm init oracleasm status fdisk -l | grep dev oracleasm createdisk ocr01 /dev/vdb1 oracleasm listdisks oracleasm renamedisk -f /dev/sdf1 asmdisk3 ------ ASM磁盘 $ORACLE_HOME/bin/kfod disk=asm s=true ds=true c=true /grid/stage/ext/bin/kfod disk=asm s=true ds=true c=true # 18c kfod disks=asm ds=true cluster=true create diskgroup DATA external redundancy disk '/dev/raw/raw*'; create diskgroup FRA external redundancy disk '/dev/rhdisk3'; --创建磁盘组FRA CREATE DISKGROUP ACFSDG external redundancy DISK '/dev/oracleasm/disks/VOL1' ATTRIBUTE 'compatible.asm' = '11.2','compatible.rdbms' = '11.2','compatible.advm'='11.2'; create diskgroup OCR external redundancy disk 'ORCL:OVDISK' attribute 'compatible.asm'='11.2','compatible.rdbms'='11.2'; CREATE DISKGROUP dgroup1 NORMAL REDUNDANCY disk '/dev/raw/raw6', '/dev/raw/raw7'; CREATE DISKGROUP dgroup1 HIGH REDUNDANCY disk '/dev/raw/raw6', '/dev/raw/raw7', '/dev/raw/raw8'; create diskgroup DG1 external redundancy failgroup FG1 disk '/dev/raw/raw6' name DG2_FG1_VOL1 failgroup FG2 disk '/dev/raw/raw7' name DG2_FG2_VOL2; create diskgroup DG2 normal redundancy failgroup FG1 disk '/dev/raw/raw6' name DG2_FG1_VOL1 failgroup FG2 disk '/dev/raw/raw7' name DG2_FG2_VOL2; create diskgroup DG2 normal redundancy failgroup FG1 disk '/dev/raw/raw6','/dev/raw/raw7' name DG2_FG1_VOL1 failgroup FG2 disk '/dev/raw/raw8','/dev/raw/raw9' name DG2_FG2_VOL2; ---修改磁盘组的兼容属性 ALTER DISKGROUP asm_dg SET ATTRIBUTE 'compatible.asm' = '11.1'; ALTER DISKGROUP asm_dg SET ATTRIBUTE 'compatible.rdbms' = '11.1'; COLUMN name FORMAT A10 COLUMN compatibility FORMAT A20 COLUMN database_compatibility FORMAT A20 SELECT group_number, name, compatibility, database_compatibility FROM v$asm_diskgroup; set line 9999 set pagesize 9999 col path format a60 SELECT a.group_number, disk_number,mount_status, a.name, path FROM v$asm_disk a order by a.disk_number; select instance_name,status from v$instance; set line 999 select name,state,free_mb,required_mirror_free_mb,usable_file_mb,a.group_number, disk_number,mount_status, path from v$asm_diskgroup a; select a.group_number,name,TYPE,state,TOTAL_MB,free_mb from v$asm_diskgroup a; select name,state,free_mb,required_mirror_free_mb,usable_file_mb,a.group_number from v$asm_diskgroup a; alter diskgroup DG1 mount; ---nomount状态下强制删除磁盘组 drop diskgroup oradg force including contents; alter diskgroup DG1 drop disk DG1_VOL5; --删除磁盘组DG1中的磁盘VOL5 alter system set asm_diskstring='','ORCL:*','/dev/raw/raw*','/dev/oracleasm/disks/VOL*'; alter system set asm_diskstring='/dev/asm-disk*','/dev/raw/raw*'; alter diskgroup DATA add disk '/dev/raw/raw1'; export GRID_HOME=$ORACLE_HOME # 查询ASM磁盘 $GRID_HOME/bin/kfod disks=asm st=true ds=true cluster=true # /grid/stage/ext/bin/kfod disks=asm st=true ds=true cluster=true ------------------------ faking asmdisk asm磁盘 ---- 添加loop设备个数 第一种办法:修改 /etc/modprobe.conf 文件添加参数:options loop max_loop=20 可以通过 modprobe -v loop 命令立即加载该模块,或重启 第二种办法(通用):mknod -m 0660 /dev/loopX b 7 X raw -qa losetup -a --mknod -m 0660 /dev/loopX b 7 X mknod -m 0660 /dev/loop9 b 7 9 mkdir /asmdisk dd if=/dev/zero of=/asmdisk/disk1 bs=1024k count=2000 dd if=/dev/zero of=/asmdisk/disk2 bs=1024k count=2000 dd if=/dev/zero of=/asmdisk/disk3 bs=1024k count=2000 dd if=/dev/zero of=/asmdisk/disk4 bs=1024k count=2000 dd if=/dev/zero of=/asmdisk/disk5 bs=1024k count=2000 /sbin/losetup /dev/loop1 /asmdisk/disk1 /sbin/losetup /dev/loop2 /asmdisk/disk2 /sbin/losetup /dev/loop3 /asmdisk/disk3 /sbin/losetup /dev/loop4 /asmdisk/disk4 /sbin/losetup /dev/loop5 /asmdisk/disk5 raw /dev/raw/raw1 /dev/loop1 raw /dev/raw/raw2 /dev/loop2 raw /dev/raw/raw3 /dev/loop3 raw /dev/raw/raw4 /dev/loop4 raw /dev/raw/raw5 /dev/loop5 chmod 660 /dev/raw/raw1 chmod 660 /dev/raw/raw2 chmod 660 /dev/raw/raw3 chmod 660 /dev/raw/raw4 chmod 660 /dev/raw/raw5 chown oracle:dba /dev/raw/raw1 chown oracle:dba /dev/raw/raw2 chown oracle:dba /dev/raw/raw3 chown oracle:dba /dev/raw/raw4 chown oracle:dba /dev/raw/raw5 ------ 将以下内容添加到文件/etc/rc.local文件中 ------Add the following entries to the file "/etc/rc.local" /sbin/losetup /dev/loop1 /asmdisk/disk1 /sbin/losetup /dev/loop2 /asmdisk/disk2 /sbin/losetup /dev/loop3 /asmdisk/disk3 /sbin/losetup /dev/loop4 /asmdisk/disk4 /sbin/losetup /dev/loop5 /asmdisk/disk5 raw /dev/raw/raw1 /dev/loop1 raw /dev/raw/raw2 /dev/loop2 raw /dev/raw/raw3 /dev/loop3 raw /dev/raw/raw4 /dev/loop4 raw /dev/raw/raw5 /dev/loop5 chmod 660 /dev/raw/raw1 chmod 660 /dev/raw/raw2 chmod 660 /dev/raw/raw3 chmod 660 /dev/raw/raw4 chmod 660 /dev/raw/raw5 chown grid:asmadmin /dev/raw/raw1 chown grid:asmadmin /dev/raw/raw2 chown grid:asmadmin /dev/raw/raw3 chown grid:asmadmin /dev/raw/raw4 chown grid:asmadmin /dev/raw/raw5 ------------------------ Simulating Asm by faking hardware -->Faking Hardware -->Instaling ASM Lib -->Configuring the disks -->Install DB & ASM instance ---Faking Hardware: root 用户 mkdir /asmdisk dd if=/dev/zero of=/asmdisk/disk1 bs=1024k count=2000 dd if=/dev/zero of=/asmdisk/disk2 bs=1024k count=2000 /sbin/losetup /dev/loop1 /asmdisk/disk1 /sbin/losetup /dev/loop2 /asmdisk/disk2 raw /dev/raw/raw1 /dev/loop1 raw /dev/raw/raw2 /dev/loop2 chmod 660 /dev/raw/raw1 chmod 660 /dev/raw/raw2 chown grid:asmadmin /dev/raw/raw1 chown grid:asmadmin /dev/raw/raw2 ------Add the following entries to the file "/etc/rc.local" echo "/sbin/losetup /dev/loop1 /asmdisk/disk1" >>/etc/rc.local echo "/sbin/losetup /dev/loop2 /asmdisk/disk2" >>/etc/rc.local |
faking出来的磁盘也可以用于ASMLIB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # mknod -m 0660 /dev/loop3 b 7 3 # losetup -d loop1 #删除loop设备 losetup -a mkdir /asmdisk dd if=/dev/zero of=/asmdisk/disk1 bs=1024k count=2000 dd if=/dev/zero of=/asmdisk/disk2 bs=1024k count=2000 dd if=/dev/zero of=/asmdisk/disk3 bs=1024k count=2000 /sbin/losetup /dev/loop1 /asmdisk/disk1 /sbin/losetup /dev/loop2 /asmdisk/disk2 /sbin/losetup /dev/loop3 /asmdisk/disk3 oracleasm createdisk ASM1 /dev/loop1 oracleasm createdisk ASM2 /dev/loop2 oracleasm createdisk ASM3 /dev/loop3 ----以下内容加入到/etc/rc.local /sbin/losetup /dev/loop1 /asmdisk/disk1 /sbin/losetup /dev/loop2 /asmdisk/disk2 /sbin/losetup /dev/loop3 /asmdisk/disk3 oracleasm scandisks # linux7下需要执行chmod +x /etc/rc.d/rc.local |
ASMLIB是什么?常用命令有哪些?其运行日志路径在哪里?
在存储管理员给服务器提供磁盘设备后,它们对于服务器来说是可用的并且可以在Linux系统中的/proc/partitions虚拟文件中可以看到。系统管理然后使用fdisk工具来对磁盘设备进行分区。被分区后磁盘设备现在可以被配置为ASMLIB磁盘,系统管理员就可以创建ASM磁盘。ASMLIB是Oracle 10g与11g中ASM功能的支持Library。ASMLIB允许Oracle数据库更有效的使用ASM与访问磁盘组。ASMLIB是ASM的一个插件,提供了一种识别与访问块设备的接口。另外,ASMLIB API能够让存储与操作系统厂商来提供存储相关的扩展功能。这些功能可能提供一些好处,比如提高性能与增加完整性,但ASMLIB对于ASM不是必须使用的。ASMLIB的一些常用命令如下所示:
l 创建ASM磁盘命令:oracleasm createdisk
l 扫描ASM磁盘命令:oracleasm scandisks
l 列举ASM磁盘命令:oracleasm listdisks
其它命令请查看官方文档。ASMLIB运行的日志文件路径在:/var/log/oracleasm。
1 2 3 4 5 6 7 8 9 10 11 | 在采用ASMLIB作为ASM驱动时,此时,通过V$ASM_DISK视图无法确认具体物理磁盘: SQL> SELECT DISK_NUMBER,PATH FROM V$ASM_DISK WHERE GROUP_NUMBER=1; DISK_NUMBER PATH ----------- ------------ 0 ORCL:VOL12 可以通过major号确定: [root@rac1 ~]# ls -l /dev/oracleasm/disks/VOL12 brw-rw---- 1 oracle oinstall 8, 29 May 15 22:02 /dev/oracleasm/disks/VOL12 [root@rac1 ~]# ls -l /dev/sd* |grep "8, 29" brw-r----- 1 root disk 8, 29 May 15 22:02 /dev/sdb13 由此可知,对应的磁盘是/dev/sdb13。 |
对于如下的磁盘:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | SQL> col name format a10 SQL> set line 9999 SQL> col path format a15 SQL> col LIBRARY format a60 SQL> select GROUP_NUMBER,path,name,disk_number,total_mb,free_mb,LIBRARY from v$asm_disk order by GROUP_NUMBER desc,disk_number; GROUP_NUMBER PATH NAME DISK_NUMBER TOTAL_MB FREE_MB LIBRARY ------------ --------------- ---------- ----------- ---------- ---------- ------------------------------------------------------------ 3 /dev/raw/raw6 FRA_0000 0 1000 992 System 3 ORCL:VOL3 FRA_0003 1 6934 6901 ASM Library - Generic Linux, version 2.0.4 (KABI_V2) 2 /dev/raw/raw1 OCR_0000 0 1000 940 System 1 /dev/raw/raw3 DATA_0000 0 1000 889 System 1 ORCL:VOL1 DATA_0003 1 9546 8530 ASM Library - Generic Linux, version 2.0.4 (KABI_V2) |
如果不能显示“ORCL:*”格式,说明asmlib没有正确加载,可以尝试重启OS。
如果LIBRARY显示System,那么需要设置asm_diskstring的值,它的值包括'/dev/oracleasm/disks/VOL*'。如果LIBRARY显示“ASM Library - Generic Linux, version 2.0.4 (KABI_V2)”,那么asm_diskstring的值可以为空或“ORCL:*”。
命令如下所示:
1 2 3 4 | alter system set asm_diskstring=''; alter system set asm_diskstring='ORCL:*','/dev/raw/raw*'; alter system set asm_diskstring='/dev/oracleasm/disks/VOL*','/dev/raw/raw*'; |
需要说明的一点是,在RHEL6(Red Hat Enterprise Linux 6)以前,Oracle均是使用ASMLIB这个内核支持库配置ASM。ASMLIB是一种基于Linux module,专门为ASM特性设计的内核支持库(kernel support library)。但是,在2011年5月,甲骨文发表了一份Oracle数据库ASMLib的声明,声明中称甲骨文将不再提供RHEL6的ASMLIB和相关更新。因此,目前在RHEL6上使用Oracle ASM,已不再使用ASMLIB,而是采用udev设备文件来配置ASM。
使用ASMLIB管理磁盘
在存储管理员给服务器提供磁盘设备后,它们对于服务器来说是可用的并且可以在Linux系统中 的/proc/partitions虚拟文件中可以看到。系统管理然后使用Linux fdisk工具来对磁盘设备进行分 区。被分区后磁盘设备现在可以被配置为ASMLIB磁盘,系统管理员创建ASMLIB磁盘。创建命 令:oracleasm createdisk。createdisk命令使用两个输入参数,通过设备来生成用户定义的磁盘名:
1 2 | [root@racnode1]#/etc/init.d/oracleasm createdisk VOL1 /dev/sdg1 Creating Oracle ASM disk "VOL1" [ OK ] |
磁盘名被限制为30个字符。它们必须使用字母开头但可以由其它ASCII字符组成,包括:大写字母, 数字和下划线。每一个被创建成功的磁盘被标识为ASMLIB磁盘并且会被显示在oracleasm文件系统 中/dev/oracleasm/disks/。文件系统是一种特定的不受任何方式进行维护。
用户可查询磁盘设备来判断是否它们是有效的ASMLIB磁盘。为了查询,使用下面的oracleasm querydisk命令。querydisk命令可以应用于裸设备和ASMLIB磁盘
1 2 3 4 | [root@racnode1]#/etc/init.d/oracleasm querydisk /dev/sdg1 Checking if device "/dev/sdg" is an Oracle ASM disk [ OK ] [root@racnode1]#/etc/init.d/oracleasm querydisk VOL1 Checking for ASM disk "VOL1" [ OK ] |
另外,所有被标记的磁盘与使用ASMLIB创建的磁盘可以使用以下oracleasm listdisks命令来显示:
1 2 3 4 | [root@racnode1]#/etc/init.d/oracleasm listdisks VOL1 VOL2 VOL3 |
如果一个磁盘设备不是一个ASMLIB磁盘,会显示以下信息:
1 2 | [root@racnode1]#/etc/init.d/oracleasm querydisk /dev/sdh1 Checking if device "/dev/sdh1" is an Oracle ASM disk [FAILED] |
对于ASM不再需要的磁盘可以撤消标记并且使用oracleasm deletedisk命令来删除:
1 2 | [root@racnode1]#/etc/init.d/oracleasm deletedisk VOL1 Deleting Oracle ASM disk "VOL1" [ OK ] |
当ASMLIB用于RAC环境时,对于RAC的共享磁盘架构允许使用oracleasm createdisk命令只在一个节点 上创建ASMLIB磁盘,其它节点只需要使用ASMLIB扫描来查找ASMLIB磁盘就可以了。例如,对于两节点 RAC环境,节点1可以标记ASMLIB磁盘,节点2然后执行扫描ASMLIB磁盘来查找这些ASMLIB磁盘。
1 2 3 4 | [root@racnode1]#/etc/init.d/oracleasm createdisk VOL1 /dev/sdg1 Creating Oracle ASM disk "VOL1" [ OK ] [root@racnode2]#/etc/init.d/oracleasm scandisks Scanning system for ASM disks [ OK ] |
在合适的ASMLIB磁盘创建后,ASM的init.ora参数asm_diskstring可以保留缺省的NULL或者设置 为'ORCL:*'。一旦设置后,ASM将可以发现以下磁盘:
1 2 3 4 5 6 | SQL> select name, library, path from v$asm_disk; NAME LIBRARY PATH ----------- ------------------------- ------------------------- VOL1 ASM Library Generic Linux ORCL:VOL1 VOL2 ASM Library Generic Linux ORCL:VOL2 VOL3 ASM Library Generic Linux ORCL:VOL3 |
注意,如果ASMLIB没有使用,那么上面的查询LIBRARY列将返回"System"。
重命名Disk
renamedisk命令被用来改变现有成员的标签而不会丢失数据。注意修改磁盘时只有当ASM不访问该磁 盘才行。因此磁盘组必须dismount,并且在RAC环境中,所有ASM节点必须都dismount磁盘组。当有 ASM实例访问被重新标签的磁盘时执行renamedisk操作可能造成损坏。因为renamedisk命令是危险的 通过打印消息可以看到:
1 2 3 4 5 6 7 8 | [root@racnode1]#/etc/init.d/oracleasm renamedisk /dev/sdb3 VOL1 Warning: Changing the label of a disk marked for ASM is a very dangerous operation. If this is really what you mean to do, you must ensure that all Oracle and ASM instances have ceased using this disk. Otherwise, you may LOSE DATA. If you really wish to change the label, rerun with the force-renamedisk command. [root@racnode1]#/etc/init.d/oracleasm force-renamedisk /dev/sdb3 VOL1 Renaming disk "/dev/sdb3" to "VOL1" [ OK ] |