Yesterday I did the lab of iSCSI in T2107 successfully. I did it again in my virtual machine. It also works. The following is the record of this lab. Thank Prof Chris Tyler for giving me help.
To configure an iSCSI Target and iSCSI Initiator on two separate systems.
I choose two machines with Fedora 10. Name machine A as iSCSI target, and machine B as initiator.
The IP address of my machine A is 192.168.189.133, B is 192.168.189.134
iSCSI Target(machine A)
1. Install the netbsd-iscsi package
#yum install netbsd-iscsi -y
2. Open a new terminal, login as user joker, and create an empty file to be shared.
$dd if=/dev/zero of=sharefile bs=1M count=100
3. Edit /etc/iscsi/targets to use that as an iSCSI target.
//Comment on the lines start with extents0 and targets0, and add two lines as below.
extent1 /home/joker/sharefile 0 100MB
target1 rw extent1 127.0.0.1/24
4. Reload the netbsd-iscsi service configuration.
#service netbsd-iscsi start
5. Verify that the iSCSI port (3260) is in use by the portal daemon.
#netstat -ant|grep 3260
tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN
iSCSI Initiator(machine B)
1. Install the iscsi-initiator-utils package.
#yum install iscsi-initiator-utils -y
2. Create an IQN and place it in /etc/iscsi/initiatorname.iscsi
//Modify the content as below.
3. Start the iscsi and iscsid services
#service iscsi start
#service iscsid start
4. Open a new terminal, login as user joker, create an SSH tunnel to the remote host (running the target/portal software).
$ssh firstname.lastname@example.org -L 3260:localhost:3260
5. Discover the remote targets
#iscsiadm -m discovery -t sendtargets -p localhost
6. List the targets
#iscsiadm -m node
7. Login to the targets
#iscsiadm -m node -l
8. Check if have an additional scsi disk device.
//I found /dev/sdb is the additional scsi disk device
9. Use /dev/sdb as one element of a RAID-1 array, using local storage as the other element.
#dd if=/dev/zero of=fakefile bs=1M count=100
#losetup /dev/loop0 fakefile
#mdadm -C /dev/md0 -l1 -n2 /dev/loop0 /dev/sdb
10. After synchronize, mount the new RAID-1 array and create a filesystem on it. Place some files there.
# mkfs.ext3 /dev/md0
# mkdir /media/raid1
# mount /dev/md0 /media/raid1
# echo “Hello World” > /media/raid1/file1
11. In machine A, mount the file system.
# mkdir /tmp/x
# mount -o loop -t ext3 sharefile /tmp/x
# ll /tmp/x
//I found the file1 file was there. Use cat to open it, it was the same with the result of machine B.
11. Go back machine B. Unmount the filesystem, stop the array, log out of the iSCSI disk
#mdadm –fail /dev/md0 /dev/loop0
#mdadm –fail /dev/md0 /dev/sdb
#mdadm -S /dev/md0
#iscsiadm -m node -u