最近發現網上關於在linux劃lv綁定裸設備建庫的文章或多或少都有很多問題,容易誤導初學者,故整理了個裸盤下直接建庫的前期操做步驟。linux
os:redhat 4.4數據庫
首先,在vm虛擬機上添加一塊硬盤,進入系統建立分區,咱們以sdc1來劃分lvoracle
[root@oracle ~]# fdisk -l –查看如今有分區app
Disk /dev/sda: 21.4 GB, 21474836480 byteside
255 heads, 63 sectors/track, 2610 cylindersspa
Units = cylinders of 16065 * 512 = 8225280 bytesrest
Device Boot Start End Blocks Id Systemorm
/dev/sda1 * 262 2610 18868342+ 83 Linux虛擬機
/dev/sda2 1 261 2096451 82 Linux swapit
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: <rawdev> <major> <minor>
# <rawdev> <blockdev>
# 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下裸設備的綁定。