最近发现网上关于在linux划lv绑定裸设备建库的文章或多或少都有不少问题,容易误导初学者,故整理了个裸盘下直接建库的前期操作步骤。
os:redhat 4.4
首先,在vm虚拟机上添加一块硬盘,进入系统创建分区,我们以sdc1来划分lv
[root@oracle ~]# fdisk -l –查看现在有分区
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 262 2610 18868342+ 83 Linux
/dev/sda2 1 261 2096451 82 Linux swap
Partition table entries are not in disk order
Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 2610 20964793+ 83 Linux
Disk /dev/sdc: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 2610 20964793+ 83 Linux
创建pv
[root@oracle ~]# pvcreate /dev/sdc1 –创建pv
Physical volume “/dev/sdc1″ successfully created
[root@oracle ~]# pvdisplay /dev/sdc1 –查看pv信息
— Physical volume —
PV Name /dev/sdc1
VG Name oradata
PV Size 19.99 GB / not usable 0
Allocatable yes
PE Size (KByte) 4096
Total PE 5118
Free PE 4955
Allocated PE 163
PV UUID ol7T1b-telA-LOqC-Z0GR-ZGqN-f01o-QJT1KC
创建vg
[root@oracle ~]# vgcreate oradata /dev/sdc1
Volume group “oradata” successfully created
[root@oracle ~]# vgdisplay –查看vg信息
— Volume group —
VG Name oradata
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 5
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 19.99 GB
PE Size 4.00 MB
Total PE 5118
Alloc PE / Size 163 / 652.00 MB
Free PE / Size 4955 / 19.36 GB
VG UUID Ohi2XZ-39PR-WH4m-WMgq-DyMY-eMZX-9CgbVi
创建lv
[root@oracle ~]# lvcreate -n system01 -L 200M oradata
Logical volume “system01″ created
[root@oracle ~]# lvcreate -n undotbs01 -L 200M oradata
Logical volume ” undotbs01″ created
[root@oracle ~]# lvcreate -n control01 -L 50M oradata
Logical volume ” control01″ created
[root@oracle ~]# lvcreate -n redo01 -L 100M oradata
Logical volume ” redo01″ created
[root@oracle ~]# lvcreate -n redo02 -L 100M oradata
Logical volume ” redo02″ created
查看lv
[root@oracle ~]# lvscan
ACTIVE ‘/dev/oradata/system01′ [200.00 MB] inherit
ACTIVE ‘/dev/oradata/undotbs’ [200.00 MB] inherit
ACTIVE ‘/dev/oradata/redo01′ [100.00 MB] inherit
ACTIVE ‘/dev/oradata/redo02′ [100.00 MB] inherit
ACTIVE ‘/dev/oradata/control01′ [52.00 MB] inherit
赋权
[root@oracle ~]# cd /dev/mapper
[root@oracle mapper]# ll
total 0
crw——- 1 root root 10, 63 Aug 21 14:28 control
brw-rw—- 1 root root 253, 4 Aug 21 18:38 oradata-control01
brw-rw—- 1 root root 253, 2 Aug 21 18:22 oradata-redo01
brw-rw—- 1 root root 253, 3 Aug 21 18:22 oradata-redo02
brw-rw—- 1 root root 253, 0 Aug 21 18:20 oradata-system01
brw-rw—- 1 root root 253, 1 Aug 21 18:21 oradata-undotbs
[root@oracle mapper]# chown -R oracle:oinstall /dev/mapper/oradata*
[root@oracle ~]# cd /dev/mapper
[root@oracle mapper]# ll
total 0
crw——- 1 root root 10, 63 Aug 21 14:28 control
brw-rw—- 1 oracle oinstall 253, 4 Aug 21 18:38 oradata-control01
brw-rw—- 1 oracle oinstall 253, 2 Aug 21 18:22 oradata-redo01
brw-rw—- 1 oracle oinstall 253, 3 Aug 21 18:22 oradata-redo02
brw-rw—- 1 oracle oinstall 253, 0 Aug 21 18:20 oradata-system01
brw-rw—- 1 oracle oinstall 253, 1 Aug 21 18:21 oradata-undotbs
[root@oracle ~]# cd /dev/oradata/
[root@oracle oradata]# ll
total 0
lrwxrwxrwx 1 root root 29 Aug 21 18:38 control01 -> /dev/mapper/oradata-control01
lrwxrwxrwx 1 root root 26 Aug 21 18:22 redo01 -> /dev/mapper/oradata-redo01
lrwxrwxrwx 1 root root 26 Aug 21 18:22 redo02 -> /dev/mapper/oradata-redo02
lrwxrwxrwx 1 root root 28 Aug 21 18:20 system01 -> /dev/mapper/oradata-system01
lrwxrwxrwx 1 root root 27 Aug 21 18:21 undotbs -> /dev/mapper/oradata-undotbs
绑定裸设备
[root@oracle oradata]# raw /dev/raw/raw1 /dev/mapper/oradata-system01 –注意,之前是没有/dev/raw目录的,执行后会自动创建
dev/raw/raw1: bound to major 253, minor 0
[root@oracle oradata]# raw /dev/raw/raw2 /dev/mapper/oradata-undotbs1
dev/raw/raw2: bound to major 253, minor 1
[root@oracle oradata]# raw /dev/raw/raw3 /dev/mapper/oradata-redo01
dev/raw/raw3: bound to major 253, minor 2
[root@oracle oradata]# raw /dev/raw/raw4 /dev/mapper/oradata-redo02
dev/raw/raw4: bound to major 253, minor 3
[root@oracle oradata]# raw /dev/raw/raw5 /dev/mapper/oradata-control01
dev/raw/raw5: bound to major 253, minor 4
为了保证重启后,可以挂载裸设备,修改下面文件,添加内容
# This file and interface are deprecated.
# Applications needing raw device access should open regular
# block devices with O_DIRECT.
# raw device bindings
# format:
#
# example: /dev/raw/raw1 /dev/sda1
# /dev/raw/raw2 8 5
/dev/raw/raw1 /dev/mapper/oradata-system01
/dev/raw/raw2 /dev/mapper/oradata-undotbs
/dev/raw/raw3 /dev/mapper/oradata-redo01
/dev/raw/raw4 /dev/mapper/oradata-redo02
/dev/raw/raw5 /dev/mapper/oradata-control01
重启裸设备服务,验证是否能挂载
[root@oracle ~]# /etc/init.d/rawdevices restart
Assigning devices:
/dev/raw/raw1 –> /dev/mapper/oradata-system01
/dev/raw/raw1: bound to major 253, minor 0
/dev/raw/raw2 –> /dev/mapper/oradata-undotbs
/dev/raw/raw2: bound to major 253, minor 1
/dev/raw/raw3 –> /dev/mapper/oradata-redo01
/dev/raw/raw3: bound to major 253, minor 2
/dev/raw/raw4 –> /dev/mapper/oradata-redo02
/dev/raw/raw4: bound to major 253, minor 3
/dev/raw/raw5 –> /dev/mapper/oradata-control01
/dev/raw/raw5: bound to major 253, minor 4
done
给新创建的裸设备增加权限,以使oracle能使用
[root@oracle ~]# cd /dev/mapper
[root@oracle mapper]# ll
total 0
crw——- 1 root root 10, 63 Aug 21 14:28 control
brw-rw—- 1 oracle oinstall 253, 4 Aug 21 18:38 oradata-control01
brw-rw—- 1 oracle oinstall 253, 2 Aug 21 18:22 oradata-redo01
brw-rw—- 1 oracle oinstall 253, 3 Aug 21 18:22 oradata-redo02
brw-rw—- 1 oracle oinstall 253, 0 Aug 21 18:20 oradata-system01
brw-rw—- 1 oracle oinstall 253, 1 Aug 21 18:21 oradata-undotbs
[root@oracle mapper]# ls -l /dev/raw
total 0
crw-rw—- 1 root disk 162, 1 Aug 21 19:43 raw1
crw-rw—- 1 root disk162, 2 Aug 21 19:43 raw2
crw-rw—- 1 root disk 162, 3 Aug 21 19:43 raw3
crw-rw—- 1 root disk 162, 4 Aug 21 19:43 raw4
crw-rw—- 1 root disk 162, 5 Aug 21 19:43 raw5
这地方的权限不能直接使用chown –R oracle:oinstall /dev/raw/raw*来修改,由于由于/dev下的文件都是动态建立的,所以在OS重启后,属主仍会变成root:disk,要解决这个问题,可以把上面的命令写入到50-udev.permissions文件中, 这样每次开机后可以重新改变属主。
修改/etc/udev/permissions.d/50-udev.permissions文件
采用:/raw搜索
将raw/*:root:disk:0660
修改为raw/*:oracle:oinstall:0660,这个的意思是修改裸设备的默认属主为oracle:oinstall,默认的mode是0660。
修改完后再通过chown –R oracle:oinstall /dev/raw/raw*来赋权。
[root@oracle ~]# cd /dev/raw/
[root@oracle raw]# ll
total 0
crw-rw—- 1 oracle oinstall 162, 1 Aug 21 19:43 raw1
crw-rw—- 1 oracle oinstall 162, 2 Aug 21 19:43 raw2
crw-rw—- 1 oracle oinstall 162, 3 Aug 21 19:43 raw3
crw-rw—- 1 oracle oinstall 162, 4 Aug 21 19:43 raw4
crw-rw—- 1 oracle oinstall 162, 5 Aug 21 19:43 raw5
随后创建软连接
[oracle@oracle prod2]$ pwd
/u01/app/oracle/oradata/prod2
[oracle@oracle prod2]$ ln -s /dev/raw/raw1 system01.dbf
[oracle@oracle prod2]$ ln –s /dev/raw/raw2 undotbs1.dbf
[oracle@oracle prod2]$ ln –s /dev/raw/raw3 redo01.rdo
[oracle@oracle prod2]$ ln –s /dev/raw/raw4 redo02.rdo
[oracle@oracle prod2]$ ln –s /dev/raw/raw5 control01.ctl
到这里为止,随后创建数据库不管你用手动建库还是dbca建基本都是差不多的操作,关键还是前面划lv和在linux下裸设备的绑定。