鸟哥学习笔记---网络驱动器设备iSCSI
生活随笔
收集整理的這篇文章主要介紹了
鸟哥学习笔记---网络驱动器设备iSCSI
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
NAS:網(wǎng)絡(luò)附加存儲(chǔ)服務(wù)器 SAN:存儲(chǔ)局域網(wǎng) 讓LinuxPC變成一臺(tái)可通過Web管理的NAS: FressNAS:http://sourceforge.net/projects/freenas/ SAN提供“磁盤”給主機(jī)用,可以格式化,分區(qū)等; NAS提供的是“網(wǎng)絡(luò)協(xié)議的文件系統(tǒng)(NFS、SMB等) iSCSI:Internet SCSI iSCSI target:相當(dāng)于服務(wù)器 iSCSI initiator:相當(dāng)于客戶端 儲(chǔ)存方式: 1.DAS:直接存儲(chǔ) 2.NAS:提供文件系統(tǒng) 3.SAN:提供磁盤 使用到的軟件: #用來將Linux系統(tǒng)仿真成為iSCSI target的功能 [root@Centosszm ~]# yum install scsi-target-utils ? ? ? ?? #用于掛載iSCSI [root@Centosszm ~]# yum install iscsi-initiator-utils 主要文件: /etc/tgt/targets.conf /usr/sbin/tgt-admin /usr/sbin/tgt-setup-lun /usr/sbin/tgtadm /usr/sbin/tgtd /usr/sbin/tgtimg 可以使用作的target: 1.文件 2.分區(qū) 3.設(shè)備 1.建立所需要的磁盤設(shè)備。 [root@Centosszm ~]# dd if=/dev/zero of=/srv/iscsi/disk1.img bs=1M count=50 50+0 records in 50+0 records out 52428800 bytes (52 MB) copied, 5.28837 s, 9.9 MB/s [root@Centosszm ~]# chcon -Rv -t tgtd_var_lib_t /srv/iscsi/ changing security context of `/srv/iscsi/disk1.img' changing security context of `/srv/iscsi/' [root@Centosszm ~]# fdisk /dev/sda [root@Centosszm ~]# partprobe #查看已掛載SWAP [root@Centosszm ~]# swapon -s Filename ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Type ? ? ? ? ? ?Size ? ?Used ? ?Priority /dev/sda7 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? partition ? ? ? 2047992 0 ? ? ? -1 [root@Centosszm ~]# pvcreate /dev/sda10 Physical volume "/dev/sda10" successfully created [root@Centosszm ~]# vgextend vg_szm /dev/sda10 Volume group "vg_szm" successfully extended [root@Centosszm ~]# lvcreate -L 50M -n iscsi01 vg_szm Rounding up size to full physical extent 52.00 MiB Logical volume "iscsi01" created [root@Centosszm ~]# lvscan ACTIVE ? ? ? ? ? ?'/dev/vg_szm/LogVol00' [8.81 GiB] inherit ACTIVE ? ? ? ? ? ?'/dev/vg_szm/iscsi01' [52.00 MiB] inherit 2.規(guī)劃共享的iSCSI target文件名:iqn(ISCSI Qualifed Name合格名稱) iqn.yyyy-mm.單位網(wǎng)絡(luò)名的反轉(zhuǎn)寫法:這個(gè)共享的target名稱 3.設(shè)置tgt [root@Centosszm ~]# hostname Centosszm.test.com [root@Centosszm ~]# vi /etc/tgt/targets.conf <target iqn.2013-04.com.Centosszm:szmdisk> backing-store /srv/iscsi/disk1.img ?#整塊磁盤用direct-store #backing-store /dev/sda8 backing-store /dev/vg_szm/iscsi01? ?#磁盤2 initiator-address 192.168.179.0/24 ?#用戶地址 incominguser szmuser szmpassword ? ?#賬號(hào)與密碼 write-cache off ? ? ? ? ? ? ? ? ? ? #關(guān)閉緩存 </target> [root@Centosszm ~]# /etc/init.d/tgtd start Starting SCSI target daemon: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [ ?OK ?] #用的是3260這個(gè)端口 [root@Centosszm ~]# netstat -tulnp | grep tgt tcp ? ? ? ?0 ? ? ?0 0.0.0.0:3260 ? ? ? ? ? ? ? ?0.0.0.0:* ? ? ? ? ? ? ? ? ? LISTEN ? ? ?2766/tgtd tcp ? ? ? ?0 ? ? ?0 :::3260 ? ? ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ? ? ? ?LISTEN ? ? ?2766/tgtd [root@Centosszm ~]# tgt-admin --show Target 1: iqn.2013-04.com.Centosszm:szmdisk System information: Driver: iscsi State: ready I_T nexus information: LUN information: LUN: 0 Type: controller ? ? ? ? ?#這個(gè)是控制器,不是可用的LUN SCSI ID: IET ? ? 00010000 SCSI SN: beaf10 Size: 0 MB Online: Yes Removable media: No Backing store type: rdwr Backing store path: None LUN: 1 Type: disk SCSI ID: IET ? ? 00010001 SCSI SN: beaf11 Size: 55 MB ? ? ? ? ? ?#磁盤大小 Online: Yes Removable media: No Backing store type: rdwr Backing store path: /dev/vg_szm/iscsi01 LUN: 2 Type: disk SCSI ID: IET ? ? 00010002 SCSI SN: beaf12 Size: 52 MB Online: Yes Removable media: No Backing store type: rdwr Backing store path: /srv/iscsi/disk1.img Account information: szmuser ? ? ? ? ?#用戶賬號(hào) ACL information: 192.168.179.0/24 ?#可連接IP #防火墻設(shè)置: [root@Centosszm ~]# iptables -A INPUT -p tcp --dport 3260 -j ACCEPT [root@Centosszm ~]# /etc/init.d/iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables:[ ?OK ?] iSCSCI initiator的設(shè)置: /etc/iscsi/iscsid.conf: /sbin/iscsid /sbin/iscsiadm /etc/init.d/iscsid /etc/init.d/iscsi ?#這個(gè)會(huì)呼叫上面那個(gè)命令 1.客戶端配置文件 [root@szm ~]# vim /etc/iscsi/iscsid.conf node.session.auth.username = szmuser ? ? ? ? ? ? ? ?#連接時(shí)用到的密碼 node.session.auth.password = szmpassword discovery.sendtargets.auth.username = szmuser discovery.sendtargets.auth.password = szmpassword ? #檢測(cè)時(shí)用到的密碼 [root@szm ~]# chkconfig iscsid on [root@szm ~]# chkconfig iscsi on 2.檢測(cè)192.168.179.7這臺(tái)target的相關(guān)數(shù)據(jù) -m discovvery: -t sendtargets: -p IP:prot : [root@szm ~]# iscsiadm -m discovery -t sendtargets -p 192.168.179.7 Starting iscsid: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [ ?OK ?] 192.168.179.7:3260,1 iqn.2013-04.com.Centosszm:szmdisk [root@szm ~]# ll -R /var/lib/iscsi/nodes/ /var/lib/iscsi/nodes/: total 4 drw-------. 3 root root 4096 Apr ?8 23:50 iqn.2013-04.com.Centosszm:szmdisk /var/lib/iscsi/nodes/iqn.2013-04.com.Centosszm:szmdisk: total 4 drw-------. 2 root root 4096 Apr ?8 23:50 192.168.179.7,3260,1 /var/lib/iscsi/nodes/iqn.2013-04.com.Centosszm:szmdisk/192.168.179.7,3260,1: total 4 -rw-------. 1 root root 1897 Apr ?8 23:50 default 3.開始進(jìn)行連接iSCSI target #找出目前本機(jī)上面所有檢測(cè)到的target信息,可能并未登錄 [root@szm ~]# iscsiadm -m node 192.168.179.7:3260,1 iqn.2013-04.com.Centosszm:szmdisk #登錄某臺(tái)target,不要重新啟動(dòng)iSCSI服務(wù) [root@szm ~]# iscsiadm -m node -T iqn.2013-04.com.Centosszm:szmdisk --login Logging in to [iface: default, target: iqn.2013-04.com.Centosszm:szmdisk, portal: 192.168.179.7,3260] (multiple) Login to [iface: default, target: iqn.2013-04.com.Centosszm:szmdisk, portal: 192.168.179.7,3260] successful. [root@szm ~]# fdisk -l …… Disk /dev/sdc: 54 MB, 54525952 bytes 2 heads, 52 sectors/track, 1024 cylinders Units = cylinders of 104 * 512 = 53248 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/sdd: 52 MB, 52428800 bytes 2 heads, 50 sectors/track, 1024 cylinders Units = cylinders of 100 * 512 = 51200 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 4.更新/刪除/添加target數(shù)據(jù)的方法 iscsiadm -m node -T targetname --logout iscsiadm -m node -o [delete|new|update] -T targetname [root@szm ~]# iscsiadm -m node -T iqn.2013-04.com.Centosszm:szmdisk --logout Logging out of session [sid: 1, target: iqn.2013-04.com.Centosszm:szmdisk, portal: 192.168.179.7,3260] Logout of [sid: 1, target: iqn.2013-04.com.Centosszm:szmdisk, portal: 192.168.179.7,3260] successful. 沒有刪除連接: [root@szm ~]# iscsiadm -m node 192.168.179.7:3260,1 iqn.2013-04.com.Centosszm:szmdisk [root@szm ~]# iscsiadm -m node -o delete -T iqn.2013-04.com.Centosszm:szmdisk [root@szm ~]# iscsiadm -m node iscsiadm: No records found #例子: [root@szm ~]# iscsiadm -m discovery -t sendtargets -p 192.168.179.7 192.168.179.7:3260,1 iqn.2013-04.com.Centosszm:szmdisk [root@szm ~]# iscsiadm -m node 192.168.179.7:3260,1 iqn.2013-04.com.Centosszm:szmdisk [root@szm ~]# /etc/init.d/iscsi restart [root@szm ~]# fdisk -l …… Disk /dev/sdc: 54 MB, 54525952 bytes 2 heads, 52 sectors/track, 1024 cylinders Units = cylinders of 104 * 512 = 53248 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/sdd: 52 MB, 52428800 bytes 2 heads, 50 sectors/track, 1024 cylinders Units = cylinders of 100 * 512 = 51200 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 [root@szm ~]# pvcreate /dev/sd{c,d} Physical volume "/dev/sdc" successfully created Physical volume "/dev/sdd" successfully created [root@szm ~]# vgcreate iscsi /dev/sd{c,d} Volume group "iscsi" successfully created [root@szm ~]# vgdisplay --- Volume group --- VG Name ? ? ? ? ? ? ? iscsi System ID Format ? ? ? ? ? ? ? ?lvm2 Metadata Areas ? ? ? ?2 Metadata Sequence No ?1 VG Access ? ? ? ? ? ? read/write VG Status ? ? ? ? ? ? resizable MAX LV ? ? ? ? ? ? ? ?0 Cur LV ? ? ? ? ? ? ? ?0 Open LV ? ? ? ? ? ? ? 0 Max PV ? ? ? ? ? ? ? ?0 Cur PV ? ? ? ? ? ? ? ?2 Act PV ? ? ? ? ? ? ? ?2 VG Size ? ? ? ? ? ? ? 96.00 MiB PE Size ? ? ? ? ? ? ? 4.00 MiB Total PE ? ? ? ? ? ? ?24 ? ? ? ? ? ?#一共24個(gè)PE Alloc PE / Size ? ? ? 0 / 0 Free ?PE / Size ? ? ? 24 / 96.00 MiB VG UUID ? ? ? ? ? ? ? nGlC74-pbo5-SrMO-29jd-xhaM-g5ds-A7lLFL [root@szm ~]# lvcreate -l 24 -n disk iscsi Logical volume "disk" created [root@szm ~]# lvdisplay --- Logical volume --- LV Path ? ? ? ? ? ? ? ?/dev/iscsi/disk LV Name ? ? ? ? ? ? ? ?disk VG Name ? ? ? ? ? ? ? ?iscsi LV UUID ? ? ? ? ? ? ? ?V8I8UH-9qrh-M671-Gph2-E36Y-jWQ5-vV0MAG LV Write Access ? ? ? ?read/write LV Creation host, time szm, 2013-04-09 13:35:07 +0800 LV Status ? ? ? ? ? ? ?available # open ? ? ? ? ? ? ? ? 0 LV Size ? ? ? ? ? ? ? ?96.00 MiB Current LE ? ? ? ? ? ? 24 Segments ? ? ? ? ? ? ? 2 Allocation ? ? ? ? ? ? inherit Read ahead sectors ? ? auto - currently set to ? ? 256 Block device ? ? ? ? ? 253:3 [root@szm ~]# mkfs -t ext4 /dev/iscsi/disk [root@szm ~]# mkdir -p /data/iscsi #_netdev:需要網(wǎng)絡(luò)開機(jī)啟動(dòng)完成后才會(huì)掛載 [root@szm ~]# vim /etc/fstab /dev/iscsi/disk ? ? ? ? /data/iscsi ? ? ? ? ? ? ext4 ? ?defaults,_netdev 1 2 [root@szm ~]# mkdir /data/iscsi/testdir [root@szm ~]# touch /data/iscsi/testdir/testfile [root@szm ~]# ll /data/iscsi/ total 14 drwx------. 2 root root 12288 Apr ?9 13:35 lost+found drwxr-xr-x. 2 root root ?1024 Apr ?9 13:39 testdir 服務(wù)器端查看: [root@Centosszm ~]# tgt-admin --show Target 1: iqn.2013-04.com.Centosszm:szmdisk System information: Driver: iscsi State: ready I_T nexus information: I_T nexus: 3 Initiator: iqn.1994-05.com.redhat:84971b47c598 ? ?#這個(gè)名字可以修改 Connection: 0 IP Address: 192.168.179.146 ? ? ? ? ? ? #連接進(jìn)來的IP LUN information: LUN: 0 Type: controller SCSI ID: IET ? ? 00010000 SCSI SN: beaf10 Size: 0 MB Online: Yes Removable media: No Backing store type: rdwr Backing store path: None LUN: 1 Type: disk SCSI ID: IET ? ? 00010001 SCSI SN: beaf11 Size: 55 MB Online: Yes Removable media: No Backing store type: rdwr Backing store path: /dev/vg_szm/iscsi01 LUN: 2 Type: disk SCSI ID: IET ? ? 00010002 SCSI SN: beaf12 Size: 52 MB Online: Yes Removable media: No Backing store type: rdwr Backing store path: /srv/iscsi/disk1.img Account information: szmuser ACL information: 192.168.179.0/24 #修改名字最好在使用前修改,否則會(huì)使得磁盤無法使用。 [root@szm ~]# cat /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.1994-05.com.szm:84971b47c598 [root@szm ~]# /etc/init.d/iscsi restart Stopping iscsi: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[ ?OK ?] Starting iscsi: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[ ?OK ?] #發(fā)生下面的改變了,郁悶,全得LV不能夠使用了。 [root@szm ~]# fdisk -l Disk /dev/sde: 54 MB, 54525952 bytes 2 heads, 52 sectors/track, 1024 cylinders Units = cylinders of 104 * 512 = 53248 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/sdf: 52 MB, 52428800 bytes 2 heads, 50 sectors/track, 1024 cylinders Units = cylinders of 100 * 512 = 51200 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
?
轉(zhuǎn)載于:https://blog.51cto.com/2816056/1184397
總結(jié)
以上是生活随笔為你收集整理的鸟哥学习笔记---网络驱动器设备iSCSI的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 两个init的区别
- 下一篇: 基于centos5.8源码安装nginx