Server information:
[[email protected] ~]# cat/etc/redhat-release CentOS release 6.6 (Final) [[email protected] ~]# uname-alinux i Nitiator 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 04:27:16 UTC x86_64 x86_64 x86_64 gnu/linux[[email protected] ~ ]# ifconfigeth0 Link encap:ethernet HWaddr 00:0c:29:6a:34:88 inet addr:192.168.221.131 bcast:192.168.221 .255 mask:255.255.255.0 Inet6 addr:fe80::20c:29ff:fe6a:3488/64 scope:link up broadcast RUNNING Multica ST mtu:1500 metric:1 RX packets:49589 errors:0 dropped:0 overruns:0 frame:0 TX packets:197750 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:3604594 6 (34.3 MiB) TX bytes:234344817 (223.4 MiB) lo Link encap:local Loopback inet addr:127.0.0.1 mask:255.0 .0.0 Inet6 Addr::: 1/128 scope:host up LOOPBACK RUNNING mtu:65536 metric:1 RX packets:4 Error s:0 dropped:0 overruns:0 frame:0 TX PacketS:4 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:276 (276.0 b) TX bytes:276 (276.0 b)
The ISCSI Initiator is a client that can use target, usually a server. If you want to connect to an iSCSI target server, you must install the relevant features of iSCSI initiator before you can use it. Its function is: 1. Can handle any file system on a locally mounted disk. 2. You do not need to restart the system after you use the FDISK command partition.
FBI Warning: Never stop the service when the LUN is still mounted on the client (initiator).
To set up iSCSI initiator you must install Iscsi-initiator-utils. Start serving ...
[[email protected] ~]# Yum Search all iSCSI loaded plugin: fastestmirrorloading mirror speeds from cached Hostfile * Base:mirro rs.skyshe.cn * extras:mirrors.skyshe.cn * updates:mirrors.cqu.edu.cn============================================== ================================== MATCHED:ISCSI =============================================================== =================iscsi-initiator-utils.x86_64:iscsi Daemon and utility programsiscsi-initiator-utils-devel.x86 _64:development files for iscsi-initiator-utilsgpxe-bootimgs.noarch:network boot loader images in bootable USB, C D, floppy and GRUB formatsgpxe-roms.noarch:network boot loader roms in. rom formatgpxe-roms-qemu.noarch:network boot L Oader ROMs supported by QEMU,. Rom formatisns-utils.x86_64:the iSNS daemon and utility programsscsi-target-utils.x86_64 : The SCSI target daemon and utility programs
1.yum Dafa Installation
[email protected] ~]# Yum install iscsi-initiator-utils iscsi-initiator-utils-devel-y
2. Start service boot
[[Email protected] ~]# Service Iscsid start is starting iscsid: [OK]
[[email protected] ~]# chkconfig iSCSI on[[email protected] ~]# chkconfig iscsid on
3.man Dafa View the client command Iscsiadm, view the sample.
EXAMPLES Discover targets at a given IP address:iscsiadm--mode discoverydb--type sendtargets--p Ortal 192.168.1.10--discover Login, must use a node record ID found by the discovery: iscsiadm--mode node--targ Etname iqn.2001-05.com.doe:test--portal 192.168.1.1:3260--login Logout: iscsiadm--mode node--targetname Iqn.2001-05.com.doe:test--portal 192.168.1.1:3260--logout List node records: iscsiadm--mode node Display all data for a given node record: iscsiadm--mode node--targetname iqn.2001-05.com.doe:test--portal 192.168 .1.1:3260
4. According to the example we find the qualified name (IQN) of the target based on IP.
[Email protected] ~]# iscsiadm--mode discoverydb--type sendtargets--portal 192.168.221.130--discover192.168.221.130 : 3260,1 IQN.2015-09.COM.NODE:TGT1
--mode discoverydb: iscsiadmin command function using detection method
--type sendtargets: Detects target data owned by the device behind the iSCSI protocol
--portal: That is the IP and port of the iSCSI device, the default for the non-writable port is 3260
Ok. Touch the clatter. Got it.
Displays all target data on the current system and may not be logged in:
[Email protected] ~]# iscsiadm-m node192.168.221.130:3260,1 IQN.2015-09.COM.NODE:TGT1
The default configuration is in the defaults file
[Email protected] ~]# ll-r/var/lib/iscsi/nodes//var/lib/iscsi/nodes/: Total dosage 4drw-------. 3 root root 4096 September 23:50 IQN.2015-09.COM.NODE:TGT1/VAR/LIB/ISCSI/NODES/IQN.2015-09.COM.NODE:TGT1: Total usage 4DRW-------. 2 root root 4096 September 23:50 192.168.221.130,3260,1/var/lib/iscsi/nodes/iqn.2015-09.com.node:tgt1/ 192.168.221.130,3260,1: Total dosage 4-rw-------. 1 root root 2045 September 23:50 Default
6. To log in, use the following command to connect a LUN to our local system, which authenticates with the server and allows us to log on to the LUN.
[Email protected] ~]# iscsiadm--mode node--targetname iqn.2015-09.com.node:tgt1--portal 192.168.221.130:3260-- Loginlogging in to [Iface:default, TARGET:IQN.2015-09.COM.NODE:TGT1, portal:192.168.221.130,3260] (multiple) Login to [ Iface:default, TARGET:IQN.2015-09.COM.NODE:TGT1, portal:192.168.221.130,3260] successful.
--targetname:target Name
--login : Login
Warning
Log out using the login command and use logout at the end of the command to replace
[Email protected] ~]# iscsiadm--mode node--targetname iqn.2015-09.com.node:tgt1--portal 192.168.221.130:3260-- Logout
Logging out of Session [Sid:1, TARGET:IQN.2015-09.COM.NODE:TGT1, portal:192.168.221.130,3260]
Logout of [Sid:1, TARGET:IQN.2015-09.COM.NODE:TGT1, portal:192.168.221.130,3260] successful.
7. After landing, display all data for a specific target
[[email protected] ~]# iscsiadm--mode node--targetname iqn.2015-09.com.node:tgt1--portal 192.168.221.130:3260# BEGIN RECORD 6.2.0-873.13.el6node.name = IQN.2015-09.COM.NODE:TGT1NODE.TPGT = 1node.startup = Automaticnode.leading_ Login = noiface.hwaddress = <empty>iface.ipaddress = <empty>iface.iscsi_ifacename = defaultiface.net_ Ifacename = <empty>iface.transport_name = Tcpiface.initiatorname = <empty>iface.state = <empty> iface.vlan_id = 0iface.vlan_priority = 0iface.vlan_state = <empty>iface.iface_num = 0IFACE.MTU = 0iface.port = 0ifac E.bootproto = <empty>iface.subnet_mask = <empty>iface.gateway = <empty>iface.dhcp_alt_client_id_ state = <empty>iface.dhcp_alt_client_id = <empty>iface.dhcp_dns = <EMPTY>IFACE.DHCP_LEARN_IQN = < Empty>iface.dhcp_req_vendor_id_state = <empty>iface.dhcp_vendor_id_state = <empty>iface.dhcp_vendor _id = <empty>iface.dhcp_slp_da = <empty>iface.fragmentation = <empty>iface.gratuitous_arp = <empty>iface.incoming_forwarding = <empty>iface.tos_state = < Empty>iface.tos = 0iface.ttl = 0
........................
8. Then list the disks that are used, and FDISK lists all the logged-on certified disks
[[email protected] ~]# fdisk-ldisk/dev/sda:21.5 GB, 21474836480 bytes255 heads, sectors/track, 2610 cylindersUn its = cylinders of 16065 * 8225280 = bytessector size (logical/physical): bytes/512 bytesi/o Size (minimum/optim AL): bytes/512 bytesdisk identifier:0x00074c40 Device Boot Start End Blocks Id system/dev/sd A1 * 1 2040 16384000 linux/dev/sda2 2040 2611 4586496 the Linux swap/ solarisdisk/dev/sdb:5368 MB, 5368709120 bytes166 heads, sectors/track, 1018 cylindersunits = cylinders of 10292 * 51 2 = 5269504 bytessector size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): bytes/512 bytesDis K identifier:0x00000000disk/dev/sdc:5368 MB, 5368709120 bytes166 heads, sectors/track, 1018 cylindersunits = Cylinde RS of 10292 * 5269504 = bytessector size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): bytes s/512 Bytesdisk Identifier:0x00000000disk/dev/sdd:5368 MB, 5368709120 bytes166 heads, $ sectors/track, 1018 cylindersunits = cylinders of 10 292 * 5269504 bytessector size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): bytes/512 Bytesdisk identifier:0x00000000disk/dev/sde:4294 MB, 4294967296 bytes133 heads, sectors/track, 1017 cylindersunits = Cylinders of 8246 * 4221952 = bytessector size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): 5 bytes/512 Bytesdisk identifier:0x00000000
9. Run the FDISK command to create a new partition, and after creating a new partition with Fdisk, we do not need to reboot, just as we do with our local file system. Because this will mount the remote shared storage locally.
[[email protected] ~]# fdisk-cu/dev/sdbdevice contains neither a valid DOS partition table, nor Sun, SGI or OSF di Sklabelbuilding a new DOS disklabel with disk identifier 0X58426CDD. Changes'll remain in memory only, until the decide to write them. After that, of course, the previous content won ' t is recoverable. Warning:invalid flag 0x0000 of partition Table 4 would be a corrected by W (rite) Command (M-help): Ncommand action E Extended p Primary partition (1-4) ppartition number (1-4): 1First sector (2048-10485759, default 2048): Using default Value 2048Last sector, +sectors or +size{k,m,g} (2048-10485759, default 10485759): Using default value 10485759Command (M For help): Tselected partition 1Hex code (type L to list codes): 83Command (M-help): pdisk/dev/sdb:5368 MB, 53687091 bytes166 heads, Sectors/track, 1018 cylinders, total 10485760 sectorsunits = sectors of 1 * = Bytessector si Ze (logical/physical): bytes/512 bytesi/o Size (Minimum/optimaL): bytes/512 bytesdisk IDENTIFIER:0X58426CDD Device Boot Start End Blocks Id system/dev/sdb 1 2048 10485759 5241856 Linuxcommand (M for help): Wthe partition table have been altered! Calling IOCTL () to re-read partition table. Syncing disks.
Do whatever you have to format the newly created partition
[[email protected] ~]# mkfs.ext4/dev/sdb1mke2fs 1.41.12 (17-may-2010) file System label = Operating system: Linux block Size =4096 (log=2) chunked size =4096 (log=2) Stride=0 blocks, Stripe width=0 blocks327680 inodes, 1310464 blocks65523 blocks (5.00%) reserved for the super User First Data block = 0Maximum filesystem blocks=134217728040 Block groups32768 blocks per group, 32768 fragments per group8192 inodes per group Superblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736 writing inode table: Complete Creating Journ Al (32768 blocks): Complete writing Superblocks and filesystem accounting information: Complete this filesystem would be automatically ch Ecked every mounts or180 days, whichever comes first. Use Tune2fs-c or-i to override.
10. Create a directory to mount the newly created partition
[Email protected] ~]# mkdir/mnt/iscsi[[email protected] ~]# mount/dev/sdb1/mnt/iscsi/
[Email protected] ~]# ls-l/mnt/iscsi/
Total dosage 16
DRWX------. 2 root root 16384 September 00:38 lost+found
Let's take a look at the mount point.
[[email protected] ~]# df-th //-t output File system type -H display size in an appropriate read filesystem type sizes used Avail use% Mounted on/dev/sda1 ext4 16G 968M 14G 7%/tmpfs tmpfs 491M 0 491M 0 %/dev/shm/dev/sdb1 ext4 4.8G 10M 4.6G 1%/MNT/ISCSI
If you want to mount it permanently, of course, the Fsab knife.
[Email protected] ~]# Vim/etc/fstab [[email protected] ~]# Cat/etc/fstab #/etc/fstab# Created by Anaconda on Tue Sep 20:53:15 2015## Accessible filesystems, by reference, is maintained under '/dev/disk ' # See mans Pages Fstab (5), Findfs ( 8), mount (8) and/or Blkid (8) For more info#uuid=0466fb2b-f1ab-4666-bb8f-2e7d008f5b55/ ext4 defaults 1 1uuid=1766dc2c-509e-4547-b647-ec42e61e9223 swap swap defaults 0 0tmpfs /dev/shm tmpfs Defaults 0 0devpts /dev/pts devpts gid=5,mode=620 0 0sysfs /sys Sysfs Defaults 0 0proc /proc proc defaults 0 0/dev/sdb1/mnt/iscsiext4defaults,_netdev 0 0
_netdev, which indicates that this is a network device.
Check our fstab file for errors.
[[email protected] ~]# Mount-av //-a all mount points-V redundancy mode MOUNT:TMPFS already mounted on/dev/shmmount:devpts already mounte D On/dev/ptsmount:sysfs already mounted on/sysmount:proc already mounted on/procmount:/DEV/SDB1 already mounted on/ Mnt/iscsinothing was mounted
Beautiful, enjoy it .....
Resources
Linux China: https://linux.cn/my favorite Linux Chinese site
Creating a centralized Secure store with iSCSI Target (a): https://linux.cn/article-4971-1.html
Brother Bird's Linux private dish--Server erection
CentOS iSCSI Server Build------Initiator Chapter