搭建iscsi服务器

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
  1. [chen@localhost 桌面]$ yum list|grep scsi  
  2. *Note* Red Hat Network repositories are not listed below. You must run this command as root to access RHN repositories.  
  3. iscsi-initiator-utils.i686             6.2.0.872-10.el6              @rhel-source  
  4. lsscsi.i686                            0.23-2.el6                    rhel-source  
  5. scsi-target-utils.i686                 1.0.4-3.el6                   rhel-source  
  6. [chen@localhost 桌面]$ su - root  
  7. 密码:  
  8. [root@localhost ~]# yum install scsi-target-utils #安装服务器端软件  
  9. Loaded plugins: refresh-packagekit, rhnplugin  
  10. This system is not registered with RHN.  
  11. RHN support will be disabled.  
  12. Setting up Install Process  
  13. Resolving Dependencies  
  14. --> Running transaction check  
  15. ---> Package scsi-target-utils.i686 0:1.0.4-3.el6 set to be updated  
  16. --> Processing Dependency: librdmacm.so.1 for package: scsi-target-utils-1.0.4-3.el6.i686  
  17. --> Processing Dependency: libibverbs.so.1 for package: scsi-target-utils-1.0.4-3.el6.i686  
  18. --> Processing Dependency: perl(Config::General) for package: scsi-target-utils-1.0.4-3.el6.i686  
  19. --> Running transaction check  
  20. ---> Package libibverbs.i686 0:1.1.4-2.el6 set to be updated  
  21. --> Processing Dependency: libibverbs-driver for package: libibverbs-1.1.4-2.el6.i686  
  22. ---> Package librdmacm.i686 0:1.0.10-2.el6 set to be updated  
  23. ---> Package perl-Config-General.noarch 0:2.44-1.el6 set to be updated  
  24. --> Running transaction check  
  25. ---> Package libmlx4.i686 0:1.0.1-7.el6 set to be updated  
  26. --> Finished Dependency Resolution  
  27.   
  28.   
  29. Dependencies Resolved  
  30.   
  31.   
  32. ================================================================================  
  33.  Package                  Arch        Version            Repository        Size  
  34. ================================================================================  
  35. Installing:  
  36.  scsi-target-utils        i686        1.0.4-3.el6        rhel-source      134 k  
  37. Installing for dependencies:  
  38.  libibverbs               i686        1.1.4-2.el6        rhel-source       43 k  
  39.  libmlx4                  i686        1.0.1-7.el6        rhel-source       27 k  
  40.  librdmacm                i686        1.0.10-2.el6       rhel-source       23 k  
  41.  perl-Config-General      noarch      2.44-1.el6         rhel-source       68 k  
  42.   
  43.   
  44. Transaction Summary  
  45. ================================================================================  
  46. Install       5 Package(s)  
  47. Upgrade       0 Package(s)  
  48.   
  49.   
  50. Total download size: 295 k  
  51. Installed size: 672 k  
  52. Is this ok [y/N]: y  
  53. Downloading Packages:  
  54. --------------------------------------------------------------------------------  
  55. Total                                           830 kB/s | 295 kB     00:00       
  56. Running rpm_check_debug  
  57. Running Transaction Test  
  58. Transaction Test Succeeded  
  59. Running Transaction  
  60.   Installing     : perl-Config-General-2.44-1.el6.noarch                    1/5   
  61.   Installing     : libmlx4-1.0.1-7.el6.i686                                 2/5   
  62.   Installing     : libibverbs-1.1.4-2.el6.i686                              3/5   
  63.   Installing     : librdmacm-1.0.10-2.el6.i686                              4/5   
  64.   Installing     : scsi-target-utils-1.0.4-3.el6.i686                       5/5   
  65.   
  66.   
  67. Installed:  
  68.   scsi-target-utils.i686 0:1.0.4-3.el6                                            
  69.   
  70.   
  71. Dependency Installed:  
  72.   libibverbs.i686 0:1.1.4-2.el6     libmlx4.i686 0:1.0.1-7.el6                   
  73.   librdmacm.i686 0:1.0.10-2.el6     perl-Config-General.noarch 0:2.44-1.el6      
  74.   
  75.   
  76. Complete!  
  77. [root@localhost ~]# ls /dev/sda*  
  78. /dev/sda   /dev/sda2  /dev/sda4  /dev/sda6  
  79. /dev/sda1  /dev/sda3  /dev/sda5  /dev/sda7  
  80. [root@localhost ~]# fdisk /dev/sda #注意服务器端要共享的盘必须是“原生”的,不能经过格式化,所以这里先分一个区  
  81.   
  82.   
  83. WARNING: DOS-compatible mode is deprecated. It's strongly recommended to  
  84.          switch off the mode (command 'c') and change display units to  
  85.          sectors (command 'u').  
  86.   
  87.   
  88. Command (m for help): n  
  89. First cylinder (1614-2610, default 1614):   
  90. Using default value 1614  
  91. Last cylinder, +cylinders or +size{K,M,G} (1614-2610, default 2610): +500M#分一个500M的  
  92.   
  93.   
  94. Command (m for help): w  
  95. The partition table has been altered!  
  96.   
  97.   
  98. Calling ioctl() to re-read partition table.  
  99.   
  100.   
  101. WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.  
  102. The kernel still uses the old table. The new table will be used at  
  103. the next reboot or after you run partprobe(8) or kpartx(8)  
  104. Syncing disks.  
  105. [root@localhost ~]# partx -a /dev/sda #刷新分区表  
  106. BLKPG: Device or resource busy  
  107. error adding partition 1  
  108. BLKPG: Device or resource busy  
  109. error adding partition 2  
  110. BLKPG: Device or resource busy  
  111. error adding partition 3  
  112. BLKPG: Device or resource busy  
  113. error adding partition 4  
  114. BLKPG: Device or resource busy  
  115. error adding partition 5  
  116. BLKPG: Device or resource busy  
  117. error adding partition 6  
  118. BLKPG: Device or resource busy  
  119. error adding partition 7  
  120. [root@localhost ~]# ls /dev/sda*  
  121. /dev/sda   /dev/sda2  /dev/sda4  /dev/sda6  /dev/sda8#可以看到有sda8了,就共享sda8  
  122. /dev/sda1  /dev/sda3  /dev/sda5  /dev/sda7  
  123. [root@localhost ~]# vim /etc/tgt/targets.conf   
  124. [root@localhost ~]# tail -5 /etc/tgt/targets.conf   
  125. #</target>  
  126. <target chen> 就加上这四行,这里这个分区的名字叫chen,redhat5中命名好像有一定格式,必须以iqn开头  
  127. backing-store /dev/sda8  
  128. initiator-address 192.169.1.100  
  129. </target>  
  130. [root@localhost ~]# /etc/init.d/tgtd start #启动服务,这样服务器端就配置完成了  
  131. 正在启动 SCSI target daemon:                              [确定]  
  132. [root@localhost ~]#   


客户端(ip:192.169.1.100):

[plain]  view plain copy
  1. [chen@localhost 桌面]$ yum list|grep scsi  
  2. scsi-target-utils.x86_64                1.0.14-2.el6                @rhel-source  
  3. iscsi-initiator-utils.x86_64            6.2.0.872-21.el6            rhel-source   
  4. lsscsi.x86_64                           0.23-2.el6                  rhel-source   
  5. [chen@localhost 桌面]$ su - root  
  6. 密码:  
  7. [root@localhost ~]# yum install -y iscsi-initiator-utils#先安装客服端  
  8. Loaded plugins: product-id, refresh-packagekit, subscription-manager  
  9. Updating Red Hat repositories.  
  10. Setting up Install Process  
  11. Resolving Dependencies  
  12. --> Running transaction check  
  13. ---> Package iscsi-initiator-utils.x86_64 0:6.2.0.872-21.el6 will be installed  
  14. --> Finished Dependency Resolution  
  15.   
  16.   
  17. Dependencies Resolved  
  18.   
  19.   
  20. ================================================================================  
  21.  Package                  Arch      Version                Repository      Size  
  22. ================================================================================  
  23. Installing:  
  24.  iscsi-initiator-utils    x86_64    6.2.0.872-21.el6       rhel-source    579 k  
  25.   
  26.   
  27. Transaction Summary  
  28. ================================================================================  
  29. Install       1 Package(s)  
  30.   
  31.   
  32. Total download size: 579 k  
  33. Installed size: 2.0 M  
  34. Downloading Packages:  
  35. Running rpm_check_debug  
  36. Running Transaction Test  
  37. Transaction Test Succeeded  
  38. Running Transaction  
  39.   Installing : iscsi-initiator-utils-6.2.0.872-21.el6.x86_64                1/1   
  40. duration: 165(ms)  
  41. Installed products updated.  
  42.   
  43.   
  44. Installed:  
  45.   iscsi-initiator-utils.x86_64 0:6.2.0.872-21.el6                                 
  46.   
  47.   
  48. Complete!  
  49. [root@localhost ~]# chkconfig --list|grep scsi #客户端服务自动开启了  
  50. iscsi           0:关闭1:关闭2:关闭3:启用4:启用5:启用6:关闭  
  51. iscsid         0:关闭1:关闭2:关闭3:启用4:启用5:启用6:关闭  
  52. [root@localhost ~]# iscsiadm -m discovery -t st -p 192.169.1.98<span style="white-space:pre">   </span>#发现服务器端是否有磁盘共享  
  53. 正在启动 iscsid:                                          [确定]  
  54. 192.169.1.98:3260,1 chen #可以看到有一个名字叫chen的磁盘,说明发现了  
  55. [root@localhost ~]# iscsiadm -m node -T chen -p 192.169.1.98 -l#登陆服务器端  
  56. Logging in to [iface: default, target: chen, portal: 192.169.1.98,3260]  
  57. Login to [iface: default, target: chen, portal: 192.169.1.98,3260] successful.#登陆成功  
  58. [root@localhost ~]# fdisk -l #查看一下本地是否多一块磁盘  
  59.   
  60.   
  61. Disk /dev/sda: 21.5 GB, 21474836480 bytes  
  62. 255 heads, 63 sectors/track, 2610 cylinders  
  63. Units = cylinders of 16065 * 512 = 8225280 bytes  
  64. Sector size (logical/physical): 512 bytes / 512 bytes  
  65. I/O size (minimum/optimal): 512 bytes / 512 bytes  
  66. Disk identifier: 0x000ee48e  
  67.   
  68.   
  69.    Device Boot      Start         End      Blocks   Id  System  
  70. /dev/sda1   *           1          26      204800   83  Linux  
  71. Partition 1 does not end on cylinder boundary.  
  72. /dev/sda2              26        1332    10485760   83  Linux  
  73. /dev/sda3            1332        1778     3584000   82  Linux swap / Solaris  
  74. /dev/sda4            1779        2610     6683040    5  Extended  
  75. /dev/sda5            1779        1831      425691   83  Linux  
  76. /dev/sda6            1832        1838       56196   83  Linux  
  77. /dev/sda7            1839        1970     1060258+  83  Linux  
  78.   
  79.   
  80. Disk /dev/sdb: 534 MB, 534610944 bytes #可以看到这边多了一块磁盘sdb,大小约为500M  
  81. 17 heads, 60 sectors/track, 1023 cylinders  
  82. Units = cylinders of 1020 * 512 = 522240 bytes  
  83. Sector size (logical/physical): 512 bytes / 512 bytes  
  84. I/O size (minimum/optimal): 512 bytes / 512 bytes  
  85. Disk identifier: 0x00000000  
  86.   
  87.   
  88. Disk /dev/sdb doesn't contain a valid partition table  
  89. [root@localhost ~]# ls /dev/sdb   
  90. /dev/sdb  
  91. [root@localhost ~]# blkid /dev/sda1  
  92. /dev/sda1: UUID="18ed3ae9-6e4f-4674-ac6d-5d763ead42ce" TYPE="ext4"    
  93. [root@localhost ~]# blkid /dev/sdb #没有uuid信息,这块磁盘是“原生”的  
  94. [root@localhost ~]# ls /dev/sdb  
  95. /dev/sdb  
  96. [root@localhost ~]# fdisk /dev/sdb #可以像本地多了一块新的磁盘一样使用这块磁盘了,这里做一个分区  
  97. Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel  
  98. Building a new DOS disklabel with disk identifier 0x945cf8be.  
  99. Changes will remain in memory only, until you decide to write them.  
  100. After that, of course, the previous content won't be recoverable.  
  101.   
  102.   
  103. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)  
  104.   
  105.   
  106. WARNING: DOS-compatible mode is deprecated. It's strongly recommended to  
  107.          switch off the mode (command 'c') and change display units to  
  108.          sectors (command 'u').  
  109.   
  110.   
  111. Command (m for help): n  
  112. Command action  
  113.    e   extended  
  114.    p   primary partition (1-4)  
  115. p  
  116. Partition number (1-4): 1  
  117. First cylinder (1-1023, default 1):   
  118. Using default value 1  
  119. Last cylinder, +cylinders or +size{K,M,G} (1-1023, default 1023): +100M#分一个100M的主分区  
  120.   
  121.   
  122. Command (m for help): p  
  123.   
  124.   
  125. Disk /dev/sdb: 534 MB, 534610944 bytes  
  126. 17 heads, 60 sectors/track, 1023 cylinders  
  127. Units = cylinders of 1020 * 512 = 522240 bytes  
  128. Sector size (logical/physical): 512 bytes / 512 bytes  
  129. I/O size (minimum/optimal): 512 bytes / 512 bytes  
  130. Disk identifier: 0x945cf8be  
  131.   
  132.   
  133.    Device Boot      Start         End      Blocks   Id  System  
  134. /dev/sdb1               1         202      102990   83  Linux  
  135.   
  136.   
  137. Command (m for help): w  
  138. The partition table has been altered!  
  139.   
  140.   
  141. Calling ioctl() to re-read partition table.  
  142. Syncing disks.  
  143. [root@localhost ~]# partx -a /dev/sdb  
  144. BLKPG: Device or resource busy  
  145. error adding partition 1  
  146. [root@localhost ~]# ls /dev/sdb*  
  147. /dev/sdb  /dev/sdb1  
  148. [root@localhost ~]# mkdir /sdb1 #创建挂载点  
  149. [root@localhost ~]# mkfs.ext4 /dev/sdb1 #格式化sdb1  
  150. mke2fs 1.41.12 (17-May-2010)  
  151. 文件系统标签=  
  152. 操作系统:Linux  
  153. 块大小=1024 (log=0)  
  154. 分块大小=1024 (log=0)  
  155. Stride=0 blocks, Stripe width=0 blocks  
  156. 25792 inodes, 102988 blocks  
  157. 5149 blocks (5.00%) reserved for the super user  
  158. 第一个数据块=1  
  159. Maximum filesystem blocks=67371008  
  160. 13 block groups  
  161. 8192 blocks per group, 8192 fragments per group  
  162. 1984 inodes per group  
  163. Superblock backups stored on blocks:   
  164. 8193, 24577, 40961, 57345, 73729  
  165.   
  166.   
  167. 正在写入inode表: 完成                              
  168. Creating journal (4096 blocks): 完成  
  169. Writing superblocks and filesystem accounting information: 完成  
  170.   
  171.   
  172. This filesystem will be automatically checked every 25 mounts or  
  173. 180 days, whichever comes first.  Use tune2fs -c or -i to override.  
  174. [root@localhost ~]# mount /dev/sdb1 /sdb1/ #挂载  
  175. [root@localhost ~]# df -hT  
  176. 文件系统    类型      容量  已用  可用 已用%% 挂载点  
  177. /dev/sda2     ext4    9.9G  3.3G  6.2G  35% /  
  178. tmpfs        tmpfs    497M  420K  497M   1% /dev/shm  
  179. /dev/sda1     ext4    194M   27M  158M  15% /boot  
  180. /dev/sda6     ext4     54M   25M   26M  50% /quota  
  181. /dev/sr0   iso9660    3.4G  3.4G     0 100% /media/RHEL_6.1 x86_64 Disc 1  
  182. /dev/sr0   iso9660    3.4G  3.4G     0 100% /mnt/iso  
  183. /dev/sdb1     ext4     98M  5.6M   87M   6% /sdb1 #可以看到的确挂载上去了,文件系统类型为ext4  
  184. [root@localhost ~]#   

注意: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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值