Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2783458
  • 博文数量: 423
  • 博客积分: 7770
  • 博客等级: 少将
  • 技术积分: 4766
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-09 11:58
个人简介

Oracle/DB2/Postgresql/Mysql/Hadoop/Greenplum/Postgres-xl/Mongodb

文章分类

全部博文(423)

文章存档

2019年(3)

2018年(6)

2017年(27)

2016年(23)

2015年(30)

2014年(16)

2013年(31)

2012年(73)

2011年(45)

2010年(14)

2009年(30)

2008年(30)

2007年(63)

2006年(32)

分类: LINUX

2012-07-12 00:35:05

通过udev配置iscsi共享磁盘名称:

来源:Linux社区  作者:t0nsha

[root@localhost ~]# udevinfo -q path -n /dev/sdb 
/block/sdb
[root@localhost ~]# /sbin/scsi_id -g -s /block/sdb
1IET     00020001
[root@localhost ~]# vim /etc/udev/rules.d/99-iscsi.rules 


KERNEL=="sd*", PROGRAM="/sbin/scsi_id -g -s %p", RESULT=="1IET     00020001", NAME="sharedisk%n"
[root@localhost ~]# vim /etc/udev/rules.d/99-myiscsi.rules  
[root@localhost ~]# service iscsi restart
Logging out of session [sid: 1, target: iqn.2012-05.com.example:ex333server.target244, portal: 192.168.221.254,3260]
Logout of [sid: 1, target: iqn.2012-05.com.example:ex333server.target244, portal: 192.168.221.254,3260]: successful
Stopping iSCSI daemon: 
iscsid dead but pid file exists                            [  OK  ]
Starting iSCSI daemon:                                     [  OK  ]
                                                           [  OK  ]
Setting up iSCSI targets: Logging in to [iface: default, target: iqn.2012-05.com.example:ex333server.demo, portal: 192.168.221.254,3260]
Logging in to [iface: default, target: iqn.2012-05.com.example:ex333server.target244, portal: 192.168.221.254,3260]
Login to [iface: default, target: iqn.2012-05.com.example:ex333server.demo, portal: 192.168.221.254,3260]: successful
Login to [iface: default, target: iqn.2012-05.com.example:ex333server.target244, portal: 192.168.221.254,3260]: successful
                                                           [  OK  ]
[root@localhost ~]# fdisk -l

Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          25      200781   83  Linux
/dev/sda2              26        1330    10482412+  83  Linux
/dev/sda3            1331        1591     2096482+  82  Linux swap / Solaris

Disk /dev/sdb: 4 MB, 4194304 bytes
1 heads, 8 sectors/track, 1024 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/sdb doesn't contain a valid partition table
[root@localhost ~]# fdisk -l /dev/sharedisk

Disk /dev/sharedisk: 4 MB, 4194304 bytes
1 heads, 8 sectors/track, 1024 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/sharedisk doesn't contain a valid partition table
[root@localhost ~]#


fdisk -l列出的是系统默认磁盘名称,要列出我们给定的磁盘名词需要写全(fdisk -l /dev/sharedisk)。


配置iscsi共享磁盘的权限:

[root@localhost rules.d]# cat /etc/passwd | grep nobody
nobody:x:99:99:Nobody:/:/sbin/nologin
[root@localhost rules.d]# vim 99-myiscsi.rules 
KERNEL=="sd*", PROGRAM="/sbin/scsi_id -g -s %p", RESULT=="1IET     00020001", SYMLINK+="sharedisk%n", OWNER="nobody", GROUP="nobody", MODE="0660"
[root@localhost rules.d]# service iscsi restart
Logging out of session [sid: 1, target: iqn.2012-05.com.example:ex333server.demo, portal: 192.168.221.254,3260]
Logging out of session [sid: 2, target: iqn.2012-05.com.example:ex333server.target244, portal: 192.168.221.254,3260]
Logout of [sid: 1, target: iqn.2012-05.com.example:ex333server.demo, portal: 192.168.221.254,3260]: successful
Logout of [sid: 2, target: iqn.2012-05.com.example:ex333server.target244, portal: 192.168.221.254,3260]: successful
Stopping iSCSI daemon: 
iscsid dead but pid file exists                            [  OK  ]
Starting iSCSI daemon:                                     [  OK  ]
                                                           [  OK  ]
Setting up iSCSI targets: Logging in to [iface: default, target: iqn.2012-05.com.example:ex333server.demo, portal: 192.168.221.254,3260]
Logging in to [iface: default, target: iqn.2012-05.com.example:ex333server.target244, portal: 192.168.221.254,3260]
Login to [iface: default, target: iqn.2012-05.com.example:ex333server.demo, portal: 192.168.221.254,3260]: successful
Login to [iface: default, target: iqn.2012-05.com.example:ex333server.target244, portal: 192.168.221.254,3260]: successful
                                                           [  OK  ]
[root@localhost rules.d]# fdisk -l

Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          25      200781   83  Linux
/dev/sda2              26        1330    10482412+  83  Linux
/dev/sda3            1331        1591     2096482+  82  Linux swap / Solaris

Disk /dev/sdb: 4 MB, 4194304 bytes
1 heads, 8 sectors/track, 1024 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/sdc: 4 MB, 4194304 bytes
1 heads, 8 sectors/track, 1024 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/sdc doesn't contain a valid partition table
[root@localhost rules.d]# fdisk -l /dev/sharedisk

Disk /dev/sharedisk: 4 MB, 4194304 bytes
1 heads, 8 sectors/track, 1024 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/sharedisk doesn't contain a valid partition table
[root@localhost rules.d]# ll /dev/sh
sharedisk  shm/       
[root@localhost rules.d]# ll /dev/sharedisk 
lrwxrwxrwx 1 root root 3 May 27 02:58 /dev/sharedisk -> sdc
[root@localhost rules.d]# ll /dev/sd*
brw-r----- 1 root   disk   8,  0 May 26 21:26 /dev/sda
brw-r----- 1 root   disk   8,  1 May 26 21:26 /dev/sda1
brw-r----- 1 root   disk   8,  2 May 26 21:26 /dev/sda2
brw-r----- 1 root   disk   8,  3 May 26 21:26 /dev/sda3
brw-r----- 1 root   disk   8, 16 May 27 02:58 /dev/sdb
brw-rw---- 1 nobody nobody 8, 32 May 27 02:58 /dev/sdc
[root@localhost rules.d]#

链接sharedisk的权限没变,不过其所指向的sdc权限已经变为我们所需要的了。

注意:双等于和单等于号不要搞混了,所有等于后面的值都要用双引号括起来,
刚开始我在写MODE这个选项时(MODE=0660)时没有用双引号,结果权限一直是-rw-r-----,
像是从umask(0022)继承过来的,但是改了umask重启iscsi服务权限确又没有随着umask走,
后面改成带引号(MODE="0660")的,然后重启iscsi服务后权限正常。

阅读(1734) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~