iscsi可以将網絡中一台機器上的磁盤共享給另一台機器
共享端叫iscsi伺服器,連接配接端叫用戶端。
實驗的伺服器環境為:
redhat6.0 32bit
ip:192.169.1.98
用戶端環境:
redhat6.1 64bit
ip:192.169.1.100
伺服器端建構
yum install scsi-target-utils #伺服器需要安裝的軟體包 vim /etc/tgt/targets.conf #配置iscsi的配置檔案 <target chen>
backing-store /dev/sdb7
initiator-address 192.169.1.100 #僅給192.169.1.100 做存儲,不加這條表示可共所有主機使用。 </target> service tgtd start chkconfig tgtd on
用戶端端建構:
yum –y install iscsi-initiator-utils #用戶端需要安裝的軟體包 iscsiadm –m discovery –t st–p 192.169.1.98#用戶端發現操作 iscsiadm -m node -T chen -p 192.169.1.98 -l#用戶端連接配接登陸
具體過程如下:
伺服器端(ip:192.169.1.98):
[plain] view plain copy
- [[email protected] 桌面]$ yum list|grep scsi
- *Note* Red Hat Network repositories are not listed below. You must run this command as root to access RHN repositories.
- iscsi-initiator-utils.i686 6.2.0.872-10.el6 @rhel-source
- lsscsi.i686 0.23-2.el6 rhel-source
- scsi-target-utils.i686 1.0.4-3.el6 rhel-source
- [[email protected] 桌面]$ su - root
- 密碼:
- [[email protected] ~]# yum install scsi-target-utils #安裝伺服器端軟體
- Loaded plugins: refresh-packagekit, rhnplugin
- This system is not registered with RHN.
- RHN support will be disabled.
- Setting up Install Process
- Resolving Dependencies
- --> Running transaction check
- ---> Package scsi-target-utils.i686 0:1.0.4-3.el6 set to be updated
- --> Processing Dependency: librdmacm.so.1 for package: scsi-target-utils-1.0.4-3.el6.i686
- --> Processing Dependency: libibverbs.so.1 for package: scsi-target-utils-1.0.4-3.el6.i686
- --> Processing Dependency: perl(Config::General) for package: scsi-target-utils-1.0.4-3.el6.i686
- --> Running transaction check
- ---> Package libibverbs.i686 0:1.1.4-2.el6 set to be updated
- --> Processing Dependency: libibverbs-driver for package: libibverbs-1.1.4-2.el6.i686
- ---> Package librdmacm.i686 0:1.0.10-2.el6 set to be updated
- ---> Package perl-Config-General.noarch 0:2.44-1.el6 set to be updated
- --> Running transaction check
- ---> Package libmlx4.i686 0:1.0.1-7.el6 set to be updated
- --> Finished Dependency Resolution
- Dependencies Resolved
- ================================================================================
- Package Arch Version Repository Size
- ================================================================================
- Installing:
- scsi-target-utils i686 1.0.4-3.el6 rhel-source 134 k
- Installing for dependencies:
- libibverbs i686 1.1.4-2.el6 rhel-source 43 k
- libmlx4 i686 1.0.1-7.el6 rhel-source 27 k
- librdmacm i686 1.0.10-2.el6 rhel-source 23 k
- perl-Config-General noarch 2.44-1.el6 rhel-source 68 k
- Transaction Summary
- ================================================================================
- Install 5 Package(s)
- Upgrade 0 Package(s)
- Total download size: 295 k
- Installed size: 672 k
- Is this ok [y/N]: y
- Downloading Packages:
- --------------------------------------------------------------------------------
- Total 830 kB/s | 295 kB 00:00
- Running rpm_check_debug
- Running Transaction Test
- Transaction Test Succeeded
- Running Transaction
- Installing : perl-Config-General-2.44-1.el6.noarch 1/5
- Installing : libmlx4-1.0.1-7.el6.i686 2/5
- Installing : libibverbs-1.1.4-2.el6.i686 3/5
- Installing : librdmacm-1.0.10-2.el6.i686 4/5
- Installing : scsi-target-utils-1.0.4-3.el6.i686 5/5
- Installed:
- scsi-target-utils.i686 0:1.0.4-3.el6
- Dependency Installed:
- libibverbs.i686 0:1.1.4-2.el6 libmlx4.i686 0:1.0.1-7.el6
- librdmacm.i686 0:1.0.10-2.el6 perl-Config-General.noarch 0:2.44-1.el6
- Complete!
- [[email protected] ~]# ls /dev/sda*
- /dev/sda /dev/sda2 /dev/sda4 /dev/sda6
- /dev/sda1 /dev/sda3 /dev/sda5 /dev/sda7
- [[email protected] ~]# fdisk /dev/sda #注意伺服器端要共享的盤必須是“原生”的,不能經過格式化,是以這裡先分一個區
- WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
- switch off the mode (command 'c') and change display units to
- sectors (command 'u').
- Command (m for help): n
- First cylinder (1614-2610, default 1614):
- Using default value 1614
- Last cylinder, +cylinders or +size{K,M,G} (1614-2610, default 2610): +500M#分一個500M的
- Command (m for help): w
- The partition table has been altered!
- Calling ioctl() to re-read partition table.
- WARNING: Re-reading the partition table failed with error 16: 裝置或資源忙.
- The kernel still uses the old table. The new table will be used at
- the next reboot or after you run partprobe(8) or kpartx(8)
- Syncing disks.
- [[email protected] ~]# partx -a /dev/sda #重新整理分區表
- BLKPG: Device or resource busy
- error adding partition 1
- BLKPG: Device or resource busy
- error adding partition 2
- BLKPG: Device or resource busy
- error adding partition 3
- BLKPG: Device or resource busy
- error adding partition 4
- BLKPG: Device or resource busy
- error adding partition 5
- BLKPG: Device or resource busy
- error adding partition 6
- BLKPG: Device or resource busy
- error adding partition 7
- [[email protected] ~]# ls /dev/sda*
- /dev/sda /dev/sda2 /dev/sda4 /dev/sda6 /dev/sda8#可以看到有sda8了,就共享sda8
- /dev/sda1 /dev/sda3 /dev/sda5 /dev/sda7
- [[email protected] ~]# vim /etc/tgt/targets.conf
- [[email protected] ~]# tail -5 /etc/tgt/targets.conf
- #</target>
- <target chen> 就加上這四行,這裡這個分區的名字叫chen,redhat5中命名好像有一定格式,必須以iqn開頭
- backing-store /dev/sda8
- initiator-address 192.169.1.100
- </target>
- [[email protected] ~]# /etc/init.d/tgtd start #啟動服務,這樣伺服器端就配置完成了
- 正在啟動 SCSI target daemon: [确定]
- [[email protected] ~]#
用戶端(ip:192.169.1.100):
[plain] view plain copy
- [[email protected] 桌面]$ yum list|grep scsi
- scsi-target-utils.x86_64 1.0.14-2.el6 @rhel-source
- iscsi-initiator-utils.x86_64 6.2.0.872-21.el6 rhel-source
- lsscsi.x86_64 0.23-2.el6 rhel-source
- [[email protected] 桌面]$ su - root
- 密碼:
- [[email protected] ~]# yum install -y iscsi-initiator-utils#先安裝客服端
- Loaded plugins: product-id, refresh-packagekit, subscription-manager
- Updating Red Hat repositories.
- Setting up Install Process
- Resolving Dependencies
- --> Running transaction check
- ---> Package iscsi-initiator-utils.x86_64 0:6.2.0.872-21.el6 will be installed
- --> Finished Dependency Resolution
- Dependencies Resolved
- ================================================================================
- Package Arch Version Repository Size
- ================================================================================
- Installing:
- iscsi-initiator-utils x86_64 6.2.0.872-21.el6 rhel-source 579 k
- Transaction Summary
- ================================================================================
- Install 1 Package(s)
- Total download size: 579 k
- Installed size: 2.0 M
- Downloading Packages:
- Running rpm_check_debug
- Running Transaction Test
- Transaction Test Succeeded
- Running Transaction
- Installing : iscsi-initiator-utils-6.2.0.872-21.el6.x86_64 1/1
- duration: 165(ms)
- Installed products updated.
- Installed:
- iscsi-initiator-utils.x86_64 0:6.2.0.872-21.el6
- Complete!
- [[email protected] ~]# chkconfig --list|grep scsi #用戶端服務自動開啟了
- iscsi 0:關閉1:關閉2:關閉3:啟用4:啟用5:啟用6:關閉
- iscsid 0:關閉1:關閉2:關閉3:啟用4:啟用5:啟用6:關閉
- [[email protected] ~]# iscsiadm -m discovery -t st -p 192.169.1.98<span style="white-space:pre"> </span>#發現伺服器端是否有磁盤共享
- 正在啟動 iscsid: [确定]
- 192.169.1.98:3260,1 chen #可以看到有一個名字叫chen的磁盤,說明發現了
- [[email protected] ~]# iscsiadm -m node -T chen -p 192.169.1.98 -l#登陸伺服器端
- Logging in to [iface: default, target: chen, portal: 192.169.1.98,3260]
- Login to [iface: default, target: chen, portal: 192.169.1.98,3260] successful.#登陸成功
- [[email protected] ~]# fdisk -l #檢視一下本地是否多一塊磁盤
- Disk /dev/sda: 21.5 GB, 21474836480 bytes
- 255 heads, 63 sectors/track, 2610 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Sector size (logical/physical): 512 bytes / 512 bytes
- I/O size (minimum/optimal): 512 bytes / 512 bytes
- Disk identifier: 0x000ee48e
- Device Boot Start End Blocks Id System
- /dev/sda1 * 1 26 204800 83 Linux
- Partition 1 does not end on cylinder boundary.
- /dev/sda2 26 1332 10485760 83 Linux
- /dev/sda3 1332 1778 3584000 82 Linux swap / Solaris
- /dev/sda4 1779 2610 6683040 5 Extended
- /dev/sda5 1779 1831 425691 83 Linux
- /dev/sda6 1832 1838 56196 83 Linux
- /dev/sda7 1839 1970 1060258+ 83 Linux
- Disk /dev/sdb: 534 MB, 534610944 bytes #可以看到這邊多了一塊磁盤sdb,大小約為500M
- 17 heads, 60 sectors/track, 1023 cylinders
- Units = cylinders of 1020 * 512 = 522240 bytes
- Sector size (logical/physical): 512 bytes / 512 bytes
- I/O size (minimum/optimal): 512 bytes / 512 bytes
- Disk identifier: 0x00000000
- Disk /dev/sdb doesn't contain a valid partition table
- [[email protected] ~]# ls /dev/sdb
- /dev/sdb
- [[email protected] ~]# blkid /dev/sda1
- /dev/sda1: UUID="18ed3ae9-6e4f-4674-ac6d-5d763ead42ce" TYPE="ext4"
- [[email protected] ~]# blkid /dev/sdb #沒有uuid資訊,這塊磁盤是“原生”的
- [[email protected] ~]# ls /dev/sdb
- /dev/sdb
- [[email protected] ~]# fdisk /dev/sdb #可以像本地多了一塊新的磁盤一樣使用這塊磁盤了,這裡做一個分區
- Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
- Building a new DOS disklabel with disk identifier 0x945cf8be.
- Changes will remain in memory only, until you decide to write them.
- After that, of course, the previous content won't be recoverable.
- Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
- WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
- switch off the mode (command 'c') and change display units to
- sectors (command 'u').
- Command (m for help): n
- Command action
- e extended
- p primary partition (1-4)
- p
- Partition number (1-4): 1
- First cylinder (1-1023, default 1):
- Using default value 1
- Last cylinder, +cylinders or +size{K,M,G} (1-1023, default 1023): +100M#分一個100M的主分區
- Command (m for help): p
- Disk /dev/sdb: 534 MB, 534610944 bytes
- 17 heads, 60 sectors/track, 1023 cylinders
- Units = cylinders of 1020 * 512 = 522240 bytes
- Sector size (logical/physical): 512 bytes / 512 bytes
- I/O size (minimum/optimal): 512 bytes / 512 bytes
- Disk identifier: 0x945cf8be
- Device Boot Start End Blocks Id System
- /dev/sdb1 1 202 102990 83 Linux
- Command (m for help): w
- The partition table has been altered!
- Calling ioctl() to re-read partition table.
- Syncing disks.
- [[email protected] ~]# partx -a /dev/sdb
- BLKPG: Device or resource busy
- error adding partition 1
- [[email protected] ~]# ls /dev/sdb*
- /dev/sdb /dev/sdb1
- [[email protected] ~]# mkdir /sdb1 #建立挂載點
- [[email protected] ~]# mkfs.ext4 /dev/sdb1 #格式化sdb1
- mke2fs 1.41.12 (17-May-2010)
- 檔案系統标簽=
- 作業系統:Linux
- 塊大小=1024 (log=0)
- 分塊大小=1024 (log=0)
- Stride=0 blocks, Stripe width=0 blocks
- 25792 inodes, 102988 blocks
- 5149 blocks (5.00%) reserved for the super user
- 第一個資料塊=1
- Maximum filesystem blocks=67371008
- 13 block groups
- 8192 blocks per group, 8192 fragments per group
- 1984 inodes per group
- Superblock backups stored on blocks:
- 8193, 24577, 40961, 57345, 73729
- 正在寫入inode表: 完成
- Creating journal (4096 blocks): 完成
- Writing superblocks and filesystem accounting information: 完成
- This filesystem will be automatically checked every 25 mounts or
- 180 days, whichever comes first. Use tune2fs -c or -i to override.
- [[email protected] ~]# mount /dev/sdb1 /sdb1/ #挂載
- [[email protected] ~]# df -hT
- 檔案系統 類型 容量 已用 可用 已用%% 挂載點
- /dev/sda2 ext4 9.9G 3.3G 6.2G 35% /
- tmpfs tmpfs 497M 420K 497M 1% /dev/shm
- /dev/sda1 ext4 194M 27M 158M 15% /boot
- /dev/sda6 ext4 54M 25M 26M 50% /quota
- /dev/sr0 iso9660 3.4G 3.4G 0 100% /media/RHEL_6.1 x86_64 Disc 1
- /dev/sr0 iso9660 3.4G 3.4G 0 100% /mnt/iso
- /dev/sdb1 ext4 98M 5.6M 87M 6% /sdb1 #可以看到的确挂載上去了,檔案系統類型為ext4
- [[email protected] ~]#
注意:iscsi服務有時候服務重新開機會出現問題,若修改配置檔案,先stop,然後start
/etc/init.d/tgtd stop
/etc/init.d/tgtd start
在用戶端
iscsiadm --mode node -T chen -p 192.169.1.98:3260 -u 登出
iscsiadm --mode node -o delete -T chen -p 192.169.1.98:3260删除chen這個發現,要先退出,再删除,删除後必須重新發現,才能登入
轉載自http://blog.csdn.net/chen_jp/article/details/7848835