2015-07-22

iSCSI 설정

iSCSI 설정

iSCSI란? goto Wiki

iSCSI는 데이터 저장소 시설을 연결하는 데 사용되는 인터넷 프로토콜 기반의 저장소 네트워킹 표준입니다. IP 네트워크상에서 SCSI 명령을 수행함으로써 iSCSI가 로컬 영역 네트워크(LAN), 광역 네트워크(WAN) 또는 인터넷에서 보다 쉽게 데이터를 전송할 수 있습니다. iSCSI를 통해 저장소 서버의 공간은 클라이언트 운영 체제에서 로컬 디스크로 간주됩니다. 그러나 실제로 디스크로 전송된 모든 데이터는 네트워크를 통해 저장소 서버로 전송됩니다.

iSCSI Target과 LUN이란?

SCSI 용어에서 LUN(논리 단위 장치 번호)은 물리적 SCSI 저장장치("Target"이라 함)의 일부인, 개별적으로 주소 지정이 가능한(논리적) SCSI 장치를 나타냅니다. iSCSI 환경에서는 가상화 방식으로 SCSI 하드 디스크로의 연결이 구현됩니다. iSCSI Target은 연결 인터페이스와 유사하며, LUN은 본질적으로 번호가 매겨진 디스크 드라이브에 해당합니다. iSCSI 개시자(클라이언트)에 의해 iSCSI Target이 연결되면 해당 iSCSI Target에 매핑된 모든 LUN이 클라이언트의 운영 체제에 가상으로 연결됩니다. 따라서 개시자가 원시 SCSI 또는 IDE 하드 드라이브에서처럼 iSCSI LUN에서 파일 시스템을 설정하고 관리할 수 있습니다.

iscsi 설정


타겟설정


● iscsi 타겟 설치

[root@fafa ~]# yum install scsi-target-utils
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirror.premi.st
* extras: mirror.premi.st
* updates: mirror.premi.st
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package scsi-target-utils.x86_64 0:1.0.24-3.el6_4 will be installed
--> Processing Dependency: perl(Config::General) for package: scsi-target-utils-1.0.24-3.el6_4.x86_64
--> Processing Dependency: librdmacm.so.1(RDMACM_1.0)(64bit) for package: scsi-target-utils-1.0.24-3.el6_4.x86_64
--> Processing Dependency: libibverbs.so.1(IBVERBS_1.1)(64bit) for package: scsi-target-utils-1.0.24-3.el6_4.x86_64
--> Processing Dependency: libibverbs.so.1(IBVERBS_1.0)(64bit) for package: scsi-target-utils-1.0.24-3.el6_4.x86_64
--> Processing Dependency: librdmacm.so.1()(64bit) for package: scsi-target-utils-1.0.24-3.el6_4.x86_64
--> Processing Dependency: libibverbs.so.1()(64bit) for package: scsi-target-utils-1.0.24-3.el6_4.x86_64
--> Running transaction check
---> Package libibverbs.x86_64 0:1.1.6-5.el6 will be installed
---> Package librdmacm.x86_64 0:1.0.17-0.git4b5c1aa.el6 will be installed
---> Package perl-Config-General.noarch 0:2.44-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package                Arch      Version                      Repository  Size
================================================================================
Installing:
scsi-target-utils      x86_64    1.0.24-3.el6_4               updates    172 k
Installing for dependencies:
libibverbs             x86_64    1.1.6-5.el6                  base        45 k
librdmacm              x86_64    1.0.17-0.git4b5c1aa.el6      base        47 k
perl-Config-General    noarch    2.44-1.el6                   base        68 k

Transaction Summary
================================================================================
Install       4 Package(s)

Total download size: 331 k
Installed size: 808 k
Is this ok [y/N]: y
Downloading Packages:
(1/4): libibverbs-1.1.6-5.el6.x86_64.rpm                 |  45 kB     00:00     
(2/4): librdmacm-1.0.17-0.git4b5c1aa.el6.x86_64.rpm      |  47 kB     00:00     
(3/4): perl-Config-General-2.44-1.el6.noarch.rpm         |  68 kB     00:00     
(4/4): scsi-target-utils-1.0.24-3.el6_4.x86_64.rpm       | 172 kB     00:00     
--------------------------------------------------------------------------------
Total                                            57 kB/s | 331 kB     00:05     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
 Installing : libibverbs-1.1.6-5.el6.x86_64                                1/4
 Installing : librdmacm-1.0.17-0.git4b5c1aa.el6.x86_64                     2/4
 Installing : perl-Config-General-2.44-1.el6.noarch                        3/4
 Installing : scsi-target-utils-1.0.24-3.el6_4.x86_64                      4/4
 Verifying  : perl-Config-General-2.44-1.el6.noarch                        1/4
 Verifying  : libibverbs-1.1.6-5.el6.x86_64                                2/4
 Verifying  : librdmacm-1.0.17-0.git4b5c1aa.el6.x86_64                     3/4
 Verifying  : scsi-target-utils-1.0.24-3.el6_4.x86_64                      4/4

Installed:
 scsi-target-utils.x86_64 0:1.0.24-3.el6_4                                     

Dependency Installed:
 libibverbs.x86_64 0:1.1.6-5.el6                                               
 librdmacm.x86_64 0:1.0.17-0.git4b5c1aa.el6                                    
 perl-Config-General.noarch 0:2.44-1.el6            
Complete!

                          

● iSCSI 타겟 데몬 서비스 등록 및 시작

[root@fafa ~]# chkconfig --list | grep tg
tgtd            0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@fafa ~]# service tgtd status
tgtd is stopped
[root@fafa ~]# service tgtd start
Starting SCSI target daemon:                               [  OK  ]
[root@fafa ~]# chkconfig --level 345 tgtd on
[root@fafa ~]# chkconfig --list | grep tg
tgtd            0:off 1:off 2:off 3:on 4:on 5:on 6:off


● iSCSI 타겟 볼륨의 이름 지정

>>>> 이름등록

[root@fafa ~]# tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2010-10.com.example.domain:storage.disk1

>>>> 타겟 리스트 출력

[root@fafa ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2010-10.com.example.domain:storage.disk1
   System information:
       Driver: iscsi
       State: ready
   I_T nexus information:
   LUN information:
       LUN: 0          <<<<< 타겟 생성시 기본으로 LUN 0번을 사용한다.
           Type: controller
           SCSI ID: IET     00010000
           SCSI SN: beaf10
           Size: 0 MB, Block size: 1
           Online: Yes
           Removable media: No
           Prevent removal: No
           Readonly: No
           Backing store type: null
           Backing store path: None
           Backing store flags:
   Account information:
   ACL information:



● 지정 iSCSI타겟볼륨에  LUN1으로서 디바이스 추가.

>>>>> 지정 타겟의 lun  (logical unit ) 1번에 ‘/dev/sdb1’ 장치 추가.
>>>>> 지정 타겟 의 tid 는 1

[root@fafa ~]# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/sdb1

>>>>>  지정 타겟의 lun 리스트 를 출력.

[root@fafa ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2010-10.com.example.domain:storage.disk1
   System information:
       Driver: iscsi
       State: ready
   I_T nexus information:
   LUN information:
       LUN: 0
           Type: controller
           SCSI ID: IET     00010000
           SCSI SN: beaf10
           Size: 0 MB, Block size: 1
           Online: Yes
           Removable media: No
           Prevent removal: No
           Readonly: No
           Backing store type: null
           Backing store path: None
           Backing store flags:
       LUN: 1    <<<<< 추가된 lun 디바이스
           Type: disk
           SCSI ID: IET     00010001
           SCSI SN: beaf11
           Size: 2147 MB, Block size: 512
           Online: Yes
           Removable media: No
           Prevent removal: No
           Readonly: No
           Backing store type: rdwr
           Backing store path: /dev/sdb1  <<<<< 추가장 장치 디바이스
           Backing store flags:
   Account information:
   ACL information:

● 타겟 디스크 /lun1에 할당된 /dev/sdb1을 삭제
>>>> 타겟 id 1에 lun 1인 볼륨을 타겟에서 제외

oot@fafa ~]# tgtadm --lld iscsi --op delete --mode logicalunit --tid 1 --lun 1

● iscisi타겟을 이미지로 설정 하기 위한 파일 생성

>>>>> 볼륨 대체용 이미지 파일 생성  512M

oot@fafa ~]# dd if=/dev/zero of=/fs.iscsi.disk bs=1M count=512





● 이미지 파일을 LUN으로 타겟에 추가.

[root@fafa ~]# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /fs.iscsi.disk
[root@fafa ~]# tgtadm --lld iscsi --op show --mode target
Target 1:  iqn.2010-10.com.example.domain:storage.disk1
   System information:
       Driver: iscsi
       State: ready
   I_T nexus information:
   LUN information:
       LUN: 0
           Type: controller
           SCSI ID: IET     00010000
           SCSI SN: beaf10
           Size: 0 MB, Block size: 1
           Online: Yes
           Removable media: No
           Prevent removal: No
           Readonly: No
           Backing store type: null
           Backing store path: None
           Backing store flags:
       LUN: 1     <<<<< 추가된 lun
           Type: disk
           SCSI ID: IET     00010001
           SCSI SN: beaf11
           Size: 537 MB, Block size: 512
           Online: Yes
           Removable media: No
           Prevent removal: No
           Readonly: No
           Backing store type: rdwr
           Backing store path: /fs.iscsi.disk      <<<< 추가된 이미지 파일
           Backing store flags:
   Account information:
   ACL information:






● selinux 를 사용하고 있다면 이미지 파일에 대한 접근을 허용한다.

[root@fafa ~]# semanage fcontext -a -t tgtd_var_lib_t /fs.iscsi.disk
[root@fafa ~]# restorecon -Rv /fs.iscsi.disk




● 이니시에터가 접속할수 있도록 타겟 바인딩

[root@fafa ~]# tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL


>>>>>  3260 포트에 바인딩 됨을 확인.

[root@fafa ~]# netstat -tulpn | grep 3260
tcp        0      0 0.0.0.0:3260                0.0.0.0:*                   LISTEN      2359/tgtd           
tcp        0      0 :::3260                     :::*                        LISTEN      2359/tgtd          










iSCSI Initiatoron 설치


● 이니시에이터 설치

[root@fafa ~]# yum install  iscsi-initiator-utils





● 이니시에이터 타겟에 접속

>>>>> 포탈에는 생성한 iSCSI 타겟의 주소를 입력한다.

[root@fafa ~]# iscsiadm --mode discovery --type sendtargets --portal 10.10.15.1
Starting iscsid:                                           [  OK  ]
10.10.15.1:3260,1iqn.2010-10.com.example.domain:storage.disk1






● 초기자가 탐색한 타겟 출력

[root@fafa ~]# iscsiadm -m node
10.10.15.1:3260,1iqn.2010-10.com.example.domain:storage.disk



● 타겟에 초기자가 로그인

>>>>  로그인이 필요한 타겟의 경우 , 필요시 /etc/iscsi/iscsid.conf 의 다음을 수정한다
>> node.session.auth.authmethod = CHAP
>>  node.session.auth.username = My_ISCSI_USR_NAME
>> node.session.auth.password = MyPassword
>> discovery.sendtargets.auth.username = My_ISCSI_USR_NAME
>> discovery.sendtargets.auth.password = MyPassword



[root@fafa ~]#  iscsiadm -m node --targetname "iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz" --portal "10.10.15.1:3260" --login
Logging in to [iface: default, target:iqn.2010-10.com.example.domain:storage.disk1, portal: 10.10.15.1,3260] (multiple)
Login to [iface: default, target:iqn.2010-10.com.example.domain:storage.disk1, portal: 10.10.15.1,3260] successful.




● fdisk -l 로 새로운 디스크 추가 확인

Disk /dev/sdf: 536 MB, 536870912 bytes
17 heads, 61 sectors/track, 1011 cylinders
Units = cylinders of 1037 * 512 = 530944 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000



● 파티션 생성및 포맷 ext4

[root@fafa ~]# fdisk /dev/sdf
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x9b4f34cc.
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-1011, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1011, default 1011):
Using default value 1011

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@fafa ~]# mkfs.ext4 /dev/sdf1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524172 blocks
26208 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
64 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@fafa ~]# fdisk  -l | grep sdf
Disk /dev/sdf: 536 MB, 536870912 bytes
/dev/sdf1               1        1011      524173   83  Linux





● 타겟제거

>>>>> iSCSI 이니시에이터가 가지는 타겟 서버로의 접속을 종료한다.
>>>>>종료시에는 fdisk -l 에  추가되었던 장치가 사라진다.

[root@fafa ~]#  iscsiadm -m node --targetname "iqn.2010-10.com.example.domain:storage.disk --portal "10.10.15.1:3260" --logout
Logging out of session [sid: 1, target:iqn.2010-10.com.example.domain:storage.disk1, portal: 10.10.15.1,3260]
Logout of [sid: 1, target:iqn.2010-10.com.example.domain:storage.disk1, portal: 10.10.15.1,3260] successful.






●  스카시 장비 확인

[root@fafa ~]# lsblk
NAME                  MAJ:MIN RM    SIZE RO TYPE MOUNTPOINT
sr0                    11:0    1   1024M  0 rom  
sda                     8:0    0     20G  0 disk
├─sda1                  8:1    0    200M  0 part /boot
├─sda2                  8:2    0    5.9G  0 part /usr
├─sda3                  8:3    0      2G  0 part [SWAP]
├─sda4                  8:4    0      1K  0 part
├─sda5                  8:5    0      2G  0 part /var
├─sda6                  8:6    0    200M  0 part /home
└─sda7                  8:7    0    9.8G  0 part /
sdb                     8:16   0      2G  0 disk
└─sdb1                  8:17   0      2G  0 part
sdc                     8:32   0      3G  0 disk
└─sdc1                  8:33   0      3G  0 part
 ├─vg00-lvol0 (dm-0) 253:0    0    300M  0 lvm  
 └─vg00-lvol1 (dm-1) 253:1    0    400M  0 lvm  
sdd                     8:48   0      1G  0 disk
└─sdd1                  8:49   0 1019.7M  0 part
sde                     8:64   0      1G  0 disk
└─sde1                  8:65   0 1019.7M  0 part
drbd0                 147:0    0 1019.7M  1 disk
drbd1                 147:1    0    300M  1 disk
sdf                     8:80   0    512M  0 disk
└─sdf1                  8:81   0  511.9M  0 part



[root@fafa ~]# sg_scan
/dev/sg0: scsi1 channel=0 id=0 lun=0 [em]
/dev/sg1: scsi2 channel=0 id=0 lun=0
/dev/sg2: scsi2 channel=0 id=1 lun=0
/dev/sg3: scsi2 channel=0 id=2 lun=0
/dev/sg4: scsi2 channel=0 id=3 lun=0
/dev/sg5: scsi2 channel=0 id=4 lun=0
/dev/sg6: scsi3 channel=0 id=0 lun=0   
/dev/sg7: scsi3 channel=0 id=0 lun=1  <<<<<< lun1 에 추가된 이미지 파일 이 scsi3 장치로 추가되어 있다.
[root@fafa ~]# sg_scan  /dev/sdf
/dev/sdf: scsi3 channel=0 id=0 lun=1 [em]





출처