ISCSI 共享存储在RHEL5上的实现方法

本文转载于  http://ylw6006.blog.51cto.com/470441/580568



ISCSI 共享存储在RHEL5上的实现方法
2011-06-03 15:35:14
版权声明:原创作品,谢绝转载!否则将追究法律责任。

  近日辉总整理了在VMware环境下安装RAC的文档,没有涉及共享存储这层概念,有点美中不足,于是我向前推进一层,使用ISCSI模拟共享存储的盘阵,研究了一翻,整理笔记内容如下,相关脚本来自唐SIR,我狗尾续貂了一把,哈哈…

环境介绍:
服务器端:RHEL5.4  64位, IP地址:192.168.50.7
客户端1:  REHL6.0  64位,IP地址:192.168.50.4
客户端2:  REHL5.4  64位,IP地址:192.168.50.195

一:服务器端:
首先需要安装scsi-target-utils工具包,然后将tgtd服务设置成开机自动启动,然后划出一个100G的LVM做共享盘阵,LVM的名称为data
[root@rhel5 ~]# yum -y install scsi-target-utils.x86_64      
[root@rhel5 ~]# service tgtd start
Starting SCSI target daemon: Starting target framework daemon
[root@rhel5 ~]# chkconfig tgtd on 
[root@rhel5 ~]# lvs
  LV          VG         Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  data        VolGroup00 -wi-ao 100.00G                                     
  lv_data     VolGroup00 -wi-ao  50.00G                                     
  lv_root     VolGroup00 -wi-ao  29.28G                                     
  oracle10g_1 VolGroup00 -wi-ao 100.00G

每次重启tgtd服务的时候,之前使用tgtdadmin绑定的target和logicalunit都会失效,因而写了个脚本用于简化操作
IQN命名规范:iqn.date. reverse.domain.name:optional name,例如:iqn.2011-06-01.com.766.rac:shareddisk
这里设置允许所有的IP进行进行挂载,取消target绑定的时候需要先取消logicalunit然后取消target

  
  
  1. [root@rhel5 ~]# cat /etc/init.d/tgtdrules   
  2. #!/bin/sh  
  3. # /etc/rc.d/init.d/oracle  
  4. # chkconfig: - 59 85  
  5. # description: oracle10g is meant to run under Linux Oracle Server  
  6. # Source function library.  
  7.  
  8. . /etc/rc.d/init.d/functions  
  9.  
  10. start() {  
  11. echo -e "Starting Tgtdrules Server:\n"  
  12.  
  13. # Target  
  14. tgtadm  --lld iscsi --op new --mode target --tid 1 -T iqn.2011-06-01.com.766.rac:shareddisk  
  15.  
  16. # Lun  
  17. tgtadm  --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/VolGroup00/data  
  18.  
  19. # Init  
  20. #tgtadm  --lld iscsi --op bind --mode target --tid 1 -I 192.168.50.191  
  21. #tgtadm  --lld iscsi --op bind --mode target --tid 1 -I 192.168.50.192  
  22. tgtadm  --lld iscsi --op bind --mode target --tid 1 -I ALL  
  23. }  
  24.  
  25. stop() {  
  26. echo -e "Stopping Tgtdrules Server:\n"  
  27.  
  28. # Lun  
  29. tgtadm  --lld iscsi --op delete --mode logicalunit --tid 1 --lun 1   
  30.  
  31. # Target  
  32. tgtadm  --lld iscsi --op delete --mode target --tid 1   
  33.  
  34. # Init  
  35. #tgtadm  --lld iscsi --op unbind --mode target --tid 1 -I 192.168.50.191  
  36. #tgtadm  --lld iscsi --op unbind --mode target --tid 1 -I 192.168.50.192  
  37. tgtadm  --lld iscsi --op unbind --mode target --tid 1 -I ALL  
  38. }  
  39.  
  40.  
  41. status() {  
  42. tgtadm --lld iscsi -o show -m target}  
  43.  
  44.  
  45. case "$1" in  
  46.  
  47.   start)  
  48.   start  
  49.   ;;  
  50.  
  51.   stop)  
  52.   stop  
  53.   ;;  
  54.  
  55.   status)  
  56.   status  
  57.   ;;  
  58.  
  59.   *)  
  60.   echo $"Usage: tgtdrules {start|stop|status}"  
  61.   ;;  
  62.  
  63. esac  
  64.  
  65. exit 0  
  66.  
  67. 服务器端测试:  
  68. [root@rhel5 ~]# service tgtd status  
  69. tgtd (pid 2943 2942) is running...  
  70.  
  71. [root@rhel5 ~]# netstat -ntpl |grep :3260  
  72. tcp        0      0 0.0.0.0:3260                0.0.0.0:*                   LISTEN      2942/tgtd             
  73. tcp        0      0 :::3260                     :::*                        LISTEN      2942/tgtd     
  74.  
  75. [root@rhel5 ~]# service tgtdrules start  
  76. Starting Tgtdrules Server:  
  77.  
  78. [root@rhel5 ~]# service tgtdrules status  
  79. Target 1: iqn.2011-06-01.com.766.rac:shareddisk  
  80.     System information:  
  81.         Driver: iscsi  
  82.         State: ready  
  83.     I_T nexus information:  
  84.         I_T nexus: 1  
  85.             Initiator: iqn.1994-05.com.redhat:b1beb63e2617  
  86.             Connection: 0  
  87.                 IP Address: 192.168.50.4  
  88.     LUN information:  
  89.         LUN: 0  
  90.             Type: controller  
  91.             SCSI ID: IET     00010000  
  92.             SCSI SN: beaf10  
  93.             Size: 0 MB  
  94.             Online: Yes  
  95.             Removable media: No  
  96.             Backing store type: null  
  97.             Backing store path: None  
  98.             Backing store flags:   
  99.         LUN: 1  
  100.             Type: disk  
  101.             SCSI ID: IET     00010001  
  102.             SCSI SN: beaf11  
  103.             Size: 107374 MB  
  104.             Online: Yes  
  105.             Removable media: No  
  106.             Backing store type: rdwr  
  107.             Backing store path: /dev/VolGroup00/data  
  108.             Backing store flags:   
  109.     Account information:  
  110.     ACL information:  
  111.     ALL 

二:客户端,RHEL6和RHEL5.4的配置基本一致,故这里以RHEL6配置为样例,省略RHEL5上的配置
安装iscsi-initiator-utils软件包,设置iscsi进程开机自动启动
[root@rhel6 /]# rpm -qa |grep iscsi
iscsi-initiator-utils-6.2.0.872-10.el6.x86_64
iscsi-initiator-utils-6.2.0.872-10.el6.i686

[root@rhel6 /]# service iscsi start
Starting iscsi: [  OK  ]
[root@rhel6 /]# chkconfig iscsi on
[root@rhel6 /]# service iscsi status
No active sessions

自动挂载iscsi脚本内容如下,挂载和卸载之前先发现,探测一次服务器端的共享是否正常

  
  
  1. [root@rhel6 /]# cat /etc/init.d/iscsiadmrules   
  2. #!/bin/bash  
  3. # /etc/rc.d/init.d/oracle  
  4. # chkconfig: - 20 85  
  5. # description: oracle9id is meant to run under Linux Oracle Server  
  6.  
  7.  
  8. # Source function library.  
  9.  
  10. . /etc/rc.d/init.d/functions  
  11.  
  12. start() {  
  13. echo -e "Starting Iscsiadmrules Server:\n"  
  14. iscsiadm --mode discovery --type sendtargets --portal 192.168.50.7  
  15. iscsiadm --mode node --targetname iqn.2011-06-01.com.766.rac:shareddisk --portal 192.168.50.7:3260 --login  
  16. }  
  17.  
  18. stop() {  
  19. echo -e "Stopping Iscsiadmrules Server:\n"  
  20. iscsiadm --mode discovery --type sendtargets --portal 192.168.50.7  
  21. iscsiadm --mode node --targetname iqn.2011-06-01.com.766.rac:shareddisk --portal 192.168.50.7:3260 --logout  
  22. }  
  23.  
  24.  
  25. case "$1" in  
  26.  
  27.  start)  
  28.  start  
  29.  ;;  
  30.  
  31.  stop)  
  32.  stop  
  33.  ;;  
  34.  
  35.  
  36. esac  
  37.  
  38. exit 0  
  39.  
  40. 挂载并查看状态  
  41. [root@rhel6 /]# service iscsiadmrules start  
  42. Starting Iscsiadmrules Server:  
  43.  
  44. 192.168.50.7:3260,1 iqn.2011-06-01.com.766.rac:shareddisk  
  45. Logging in to [iface: default, target: iqn.2011-06-01.com.766.rac:shareddisk, portal: 192.168.50.7,3260]  
  46. Login to [iface: default, target: iqn.2011-06-01.com.766.rac:shareddisk, portal: 192.168.50.7,3260] successful.  
  47.  
  48. [root@rhel6 /]# service iscsi status  
  49. iSCSI Transport Class version 2.0-870  
  50. version 2.0-872  
  51. Target: iqn.2011-06-01.com.766.rac:shareddisk  
  52.         Current Portal: 192.168.50.7:3260,1  
  53.         Persistent Portal: 192.168.50.7:3260,1  
  54.                 **********  
  55.                 Interface:  
  56.                 **********  
  57.                 Iface Name: default  
  58.                 Iface Transport: tcp  
  59.                 Iface Initiatorname: iqn.1994-05.com.redhat:b1beb63e2617  
  60.                 Iface IPaddress: 192.168.50.4  
  61.                 Iface HWaddress: <empty> 
  62.                 Iface Netdev: <empty> 
  63.                 SID: 11  
  64.                 iSCSI Connection State: LOGGED IN  
  65.                 iSCSI Session State: LOGGED_IN  
  66.                 Internal iscsid Session State: NO CHANGE  
  67.                 ************************  
  68.                 Negotiated iSCSI params:  
  69.                 ************************  
  70.                 HeaderDigest: None  
  71.                 DataDigest: None  
  72.                 MaxRecvDataSegmentLength: 262144  
  73.                 MaxXmitDataSegmentLength: 8192  
  74.                 FirstBurstLength: 65536  
  75.                 MaxBurstLength: 262144  
  76.                 ImmediateData: Yes  
  77.                 InitialR2T: Yes  
  78.                 MaxOutstandingR2T: 1  
  79.                 ************************  
  80.                 Attached SCSI devices:  
  81.                 ************************  
  82.                 Host Number: 18 State: running  
  83.                 scsi18 Channel 00 Id 0 Lun: 0  
  84.                 scsi18 Channel 00 Id 0 Lun: 1  
  85.                         Attached scsi disk sdb          State: running 

三:验证共享存储是否正常 

  
  
  1. RHEL6                     
  2. [root@rhel6 /]# fdisk -l  
  3.  
  4. Disk /dev/sda: 160.0 GB, 160041885696 bytes  
  5. 255 heads, 63 sectors/track, 19457 cylinders  
  6. Units = cylinders of 16065 * 512 = 8225280 bytes  
  7. Sector size (logical/physical): 512 bytes / 512 bytes  
  8. I/O size (minimum/optimal): 512 bytes / 512 bytes  
  9. Disk identifier: 0x00080dc2                       
  10.                           
  11.     Device Boot      Start         End      Blocks   Id  System  
  12. /dev/sda1   *           1          13      102400   83  Linux  
  13. /dev/sda2              13         523     4096000   82  Linux swap / Solaris  
  14. /dev/sda3             523         778     2048000   83  Linux  
  15. /dev/sda4             778       19458   150042624    5  Extended  
  16. /dev/sda5             778       19458   150041600   8e  Linux LVM     
  17.  
  18. Disk /dev/sdb: 107.4 GB, 107374182400 bytes  
  19. 255 heads, 63 sectors/track, 13054 cylinders  
  20. Units = cylinders of 16065 * 512 = 8225280 bytes  
  21. Sector size (logical/physical): 512 bytes / 512 bytes  
  22. I/O size (minimum/optimal): 512 bytes / 512 bytes  
  23. Disk identifier: 0x00000000  
  24.  
  25. Disk /dev/sdb doesn't contain a valid partition table                 
  26.                                       
  27. [root@rhel6 /]# service iscsiadmrules stop  
  28. Stopping Iscsiadmrules Server:  
  29.  
  30. 192.168.50.7:3260,1 iqn.2011-06-01.com.766.rac:shareddisk  
  31. Logging out of session [sid: 11, target: iqn.2011-06-01.com.766.rac:shareddisk, portal: 192.168.50.7,3260]  
  32. Logout of [sid: 11, target: iqn.2011-06-01.com.766.rac:shareddisk, portal: 192.168.50.7,3260] successful.  
  33. [root@rhel6 /]# service iscsi status  
  34. No active sessions        
  35.  
  36. RHEL5.4           
  37. [root@ora10g ~]# fdisk -l  
  38. Disk /dev/vda: 107.3 GB, 107374182400 bytes  
  39. 255 heads, 63 sectors/track, 13054 cylinders  
  40. Units = cylinders of 16065 * 512 = 8225280 bytes  
  41.  
  42.    Device Boot      Start         End      Blocks   Id  System  
  43. /dev/vda1   *           1          13      104391   83  Linux  
  44. /dev/vda2              14         523     4096575   82  Linux swap / Solaris  
  45. /dev/vda3             524         778     2048287+  83  Linux  
  46. /dev/vda4             779       13054    98606970    5  Extended  
  47. /dev/vda5             779       13054    98606938+  8e  Linux LVM  
  48.  
  49. Disk /dev/sda: 107.3 GB, 107374182400 bytes  
  50. 255 heads, 63 sectors/track, 13054 cylinders  
  51. Units = cylinders of 16065 * 512 = 8225280 bytes  
  52.  
  53. Disk /dev/sda doesn't contain a valid partition table                        

 

本文出自 “斩月” 博客,谢绝转载!







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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值