[Linux] Configure iSCSI on Linux5 (both target and initiator)


************************************************************
********************Target********************************
************************************************************


[root@node3 ~]# yum list installed | grep scsi
iscsi-initiator-utils.x86_64 6.2.0.872-16.el5 installed ★initiator Only, Target rpm needed
[root@node3 ~]# yum install scsi-target-utils ★install Target
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package scsi-target-utils.x86_64 0:1.0.14-2.el5 set to be updated
--> Processing Dependency: libibverbs.so.1(IBVERBS_1.1)(64bit) for package: scsi-target-utils
--> Processing Dependency: librdmacm.so.1(RDMACM_1.0)(64bit) for package: scsi-target-utils
--> Processing Dependency: perl(Config::General) for package: scsi-target-utils
--> Processing Dependency: libibverbs.so.1()(64bit) for package: scsi-target-utils
--> Processing Dependency: librdmacm.so.1()(64bit) for package: scsi-target-utils
--> Running transaction check
---> Package libibverbs.x86_64 0:1.1.6-3.el5 set to be updated
--> Processing Dependency: openib >= 1.0 for package: libibverbs
---> Package librdmacm.x86_64 0:1.0.15-2.el5 set to be updated
---> Package perl-Config-General.noarch 0:2.40-1.el5 set to be updated
--> Running transaction check
---> Package openib.noarch 0:1.5.4.1-4.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================================================================================================================
Package Arch Version Repository Size
================================================================================================================================================================================================================
Installing:
scsi-target-utils x86_64 1.0.14-2.el5 base 172 k
Installing for dependencies:
libibverbs x86_64 1.1.6-3.el5 base 46 k
librdmacm x86_64 1.0.15-2.el5 base 28 k
openib noarch 1.5.4.1-4.el5 base 23 k
perl-Config-General noarch 2.40-1.el5 base 68 k

Transaction Summary
================================================================================================================================================================================================================
Install 5 Package(s)
Upgrade 0 Package(s)

Total download size: 337 k
Is this ok [y/N]: y
Downloading Packages:
(1/5): openib-1.5.4.1-4.el5.noarch.rpm | 23 kB 00:00
(2/5): librdmacm-1.0.15-2.el5.x86_64.rpm | 28 kB 00:00
(3/5): libibverbs-1.1.6-3.el5.x86_64.rpm | 46 kB 00:00
(4/5): perl-Config-General-2.40-1.el5.noarch.rpm | 68 kB 00:00
(5/5): scsi-target-utils-1.0.14-2.el5.x86_64.rpm | 172 kB 00:00
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 151 kB/s | 337 kB 00:02
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : perl-Config-General 1/5
Installing : openib 2/5
Installing : libibverbs 3/5
Installing : librdmacm 4/5
Installing : scsi-target-utils 5/5

Installed:
scsi-target-utils.x86_64 0:1.0.14-2.el5

Dependency Installed:
libibverbs.x86_64 0:1.1.6-3.el5 librdmacm.x86_64 0:1.0.15-2.el5 openib.noarch 0:1.5.4.1-4.el5 perl-Config-General.noarch 0:2.40-1.el5

Complete! ★
[root@node3 ~]# yum list installed | grep scsi
iscsi-initiator-utils.x86_64 6.2.0.872-16.el5 installed
scsi-target-utils.x86_64 1.0.14-2.el5 installed ★Target rpm is installed
[root@node3 ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
#127.0.0.1 localhost.localdomain localhost
#::1 localhost6.localdomain6 localhost6

127.0.0.1 node3 localhost
#172.16.20.34 node2 localhost

192.168.56.105 node2 ★initiator
192.168.56.104 node3 ★Target

[root@node3 ~]# ping node2 ★ping to initiator ,No problem
PING node2 (192.168.56.105) 56(84) bytes of data.
64 bytes from node2 (192.168.56.105): icmp_seq=1 ttl=64 time=2.43 ms
64 bytes from node2 (192.168.56.105): icmp_seq=2 ttl=64 time=1.06 ms

--- node2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 1.064/1.748/2.432/0.684 ms
[root@node3 ~]# fdisk -l ★Check Disk info

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 3916 31350847+ 8e Linux LVM

Disk /dev/sdb: 2147 MB, 2147483648 bytes ★Test Disk, No disk partition
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

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

Disk /dev/dm-0: 25.8 GB, 25836912640 bytes
255 heads, 63 sectors/track, 3141 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/dm-0 doesn't contain a valid partition table

Disk /dev/dm-1: 6241 MB, 6241124352 bytes
255 heads, 63 sectors/track, 758 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/dm-1 doesn't contain a valid partition table
[root@node3 ~]# fdisk /dev/sdb ★Create disk partition
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. 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)

Command (m for help): n ★
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1 ★
First cylinder (1-261, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261):
Using default value 261

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@node3 ~]# partprobe /dev/sdb ★
[root@node3 ~]# fdisk -l ★

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 3916 31350847+ 8e Linux LVM

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 83 Linux ★Done

Disk /dev/dm-0: 25.8 GB, 25836912640 bytes
255 heads, 63 sectors/track, 3141 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/dm-0 doesn't contain a valid partition table

Disk /dev/dm-1: 6241 MB, 6241124352 bytes
255 heads, 63 sectors/track, 758 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/dm-1 doesn't contain a valid partition table

[root@node3 ~]# more /etc/tgt/targets.conf ★
# This is a sample config file for tgt-admin.
# By default, tgt-admin looks for its config file in /etc/tgt/targets.conf
#
# The "#" symbol disables the processing of a line.


# This one includes other config files:

#include /etc/tgt/temp/*.conf


# Set the driver. If not specified, defaults to "iscsi".

default-driver iscsi

....
[root@node3 ~]# vi /etc/tgt/targets.conf ★rectify configuration file , between tag <target..</target>
[root@node3 ~]# more /etc/tgt/targets.conf
<target qn.2001-04.com.jp-lin03-sdb:tgtd> ★
backing-store /dev/sdb1 ★
initiator-address 192.168.56.105 ★
</target> ★

# This is a sample config file for tgt-admin.
# By default, tgt-admin looks for its config file in /etc/tgt/targets.conf
#
# The "#" symbol disables the processing of a line.


# This one includes other config files:

#include /etc/tgt/temp/*.conf


# Set the driver. If not specified, defaults to "iscsi".

default-driver iscsi

....

[root@node3 ~]# service tgtd start ★start tgtd service
Starting SCSI target daemon: Starting target framework daemon

[root@node3 ~]# chkconfig tgtd on ★bring tgtd service up automatically next time when the OS starts
[root@node3 ~]# chkconfig --list tgtd ★
tgtd 0:off 1:off 2:on 3:on 4:on 5:on 6:off ★OK
[root@node3 ~]# netstat -tulnp | grep tgtd ★find the Port number of iscsi target
tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN 4141/tgtd
[root@node3 ~]# iptables -L ★
Chain INPUT (policy ACCEPT)
target prot opt source destination
RH-Firewall-1-INPUT all -- anywhere anywhere

Chain FORWARD (policy ACCEPT)
target prot opt source destination
RH-Firewall-1-INPUT all -- anywhere anywhere

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

Chain RH-Firewall-1-INPUT (2 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT icmp -- anywhere anywhere icmp any
ACCEPT esp -- anywhere anywhere
ACCEPT ah -- anywhere anywhere
ACCEPT udp -- anywhere 224.0.0.251 udp dpt:mdns
ACCEPT udp -- anywhere anywhere udp dpt:ipp
ACCEPT tcp -- anywhere anywhere tcp dpt:ipp
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ftp
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:nfs
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:telnet
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

.... ★Add Firewall port rules from GUI(tcp and udp on port 3260)
[root@node3 ~]# iptables -L ★
Chain INPUT (policy ACCEPT)
target prot opt source destination
RH-Firewall-1-INPUT all -- anywhere anywhere

Chain FORWARD (policy ACCEPT)
target prot opt source destination
RH-Firewall-1-INPUT all -- anywhere anywhere

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

Chain RH-Firewall-1-INPUT (2 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT icmp -- anywhere anywhere icmp any
ACCEPT esp -- anywhere anywhere
ACCEPT ah -- anywhere anywhere
ACCEPT udp -- anywhere 224.0.0.251 udp dpt:mdns
ACCEPT udp -- anywhere anywhere udp dpt:ipp
ACCEPT tcp -- anywhere anywhere tcp dpt:ipp
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ftp
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:nfs
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:telnet
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:iscsi-target ★
ACCEPT udp -- anywhere anywhere state NEW udp dpt:iscsi-target ★
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

[root@node3 ~]# tgt-admin -s ★Check Target service
Target 1: qn.2001-04.com.jp-lin03-sdb:tgtd
System information:
Driver: iscsi
State: ready ★OK
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
Readonly: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 2147 MB, Block size: 512
Online: Yes
Removable media: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/sdb1 ★OK
Backing store flags:
Account information:
ACL information:
192.168.56.105


************************************************************
********************Initiator****************************
************************************************************
[root@node2 ~]# yum list installed | grep scsi ★
iscsi-initiator-utils.x86_64 6.2.0.872-16.el5 installed ★
[root@node2 ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
#127.0.0.1 localhost.localdomain localhost
#::1 localhost6.localdomain6 localhost6

127.0.0.1 node2 localhost

192.168.56.105 node2
192.168.56.104 node3

[root@node2 ~]# cat /etc/iscsi/initiatorname.iscsi
#InitiatorName=iqn.1994-05.com.redhat:ca542ec6f39b
#InitiatorName=iqn.2001-04.com.example:node2 ★
[root@node2 ~]# vi /etc/iscsi/initiatorname.iscsi ★rectify configuration file
[root@node2 ~]# cat /etc/iscsi/initiatorname.iscsi
#InitiatorName=iqn.1994-05.com.redhat:ca542ec6f39b
InitiatorName=iqn.2001-04.com.example:node2 ★
[root@node2 ~]# /etc/init.d/iscsi restart ★restart
iscsiadm: No matching sessions found
Stopping iSCSI daemon:
iscsid は停止しています [ OK ]
Starting iSCSI daemon: [ OK ]
[ OK ]
iSCSI ターゲットを設定中: Logging in to [iface: default, target: qn.2001-04.com.jp-lin03-sdb:tgtd, portal: 192.168.56.104,3260] (multiple)
Login to [iface: default, target: qn.2001-04.com.jp-lin03-sdb:tgtd, portal: 192.168.56.104,3260] successful.
[ OK ]
[root@node2 ~]# fdisk -l ★

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 3916 31350847+ 8e Linux LVM

Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

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

Disk /dev/dm-0: 46.2 GB, 46238007296 bytes
255 heads, 63 sectors/track, 5621 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/dm-0 doesn't contain a valid partition table

Disk /dev/dm-1: 6241 MB, 6241124352 bytes
255 heads, 63 sectors/track, 758 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/dm-1 doesn't contain a valid partition table

Disk /dev/sdc: 2146 MB, 2146765824 bytes ★Worked
67 heads, 62 sectors/track, 1009 cylinders
Units = cylinders of 4154 * 512 = 2126848 bytes

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

猜你喜欢

转载自www.cnblogs.com/Frank-20160505/p/10288376.html