CentOS iSCSI伺服器搭建------Initiator篇

來源:互聯網
上載者:User

標籤:

伺服器資訊:

[[email protected] ~]# cat /etc/redhat-release CentOS release 6.6 (Final)[[email protected] ~]# uname -aLinux initiator 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 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 MULTICAST  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:36045946 (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 errors: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)

  

 iSCSI initiator是能夠使用target的用戶端,通常是伺服器。想要串連到iSCSI target的伺服器,必須要安裝iSCSI initiator的相關功能後才可以使用。其功能是:1.可以處理本地掛載磁碟上的任意檔案系統。2.在使用fdisk命令分區後不需要重啟系統。

FBI Warning:永遠不要在LUN還掛載在用戶端(啟動器)時停止服務。

  要設定iSCSI initiator 必須要安裝iscsi-initiator-utils才行。開始上菜。。。

[[email protected] ~]#  yum search all iscsi已載入外掛程式:fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.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, CD, floppy and GRUB formatsgpxe-roms.noarch : Network boot loader roms in .rom formatgpxe-roms-qemu.noarch : Network boot loader 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大法安裝

[[email protected] ~]# yum install iscsi-initiator-utils iscsi-initiator-utils-devel -y

2.啟動服務開機啟動

[[email protected] ~]# service iscsid start正在啟動 iscsid:                                          [確定]
[[email protected] ~]# chkconfig iscsi on[[email protected] ~]# chkconfig iscsid on

3.man大法查看用戶端命令iscsiadm,查看樣本。

EXAMPLES       Discover targets at a given IP address:            iscsiadm --mode discoverydb --type sendtargets --portal 192.168.1.10 --discover       Login, must use a node record id found by the discovery:            iscsiadm --mode node --targetname 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.根據樣本中我們根據IP找到Target的限定名(iqn)。

[[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命令功能

  --type sendtargets :通過iSCSI的協議,檢測後面的裝置所擁有的target資料

  --portal                 :就是那台iSCSI裝置的IP與連接埠,不寫連接埠的預設是3260

OK。摸摸噠。找到了。

顯示出目前系統上面所有的target資料,可能並未登陸:

[[email protected] ~]# iscsiadm -m node192.168.221.130:3260,1 iqn.2015-09.com.node:tgt1

預設配置都在defaults檔案中

[[email protected] ~]# ll -R /var/lib/iscsi/nodes//var/lib/iscsi/nodes/:總用量 4drw-------. 3 root root 4096 9月  22 23:50 iqn.2015-09.com.node:tgt1/var/lib/iscsi/nodes/iqn.2015-09.com.node:tgt1:總用量 4drw-------. 2 root root 4096 9月  22 23:50 192.168.221.130,3260,1/var/lib/iscsi/nodes/iqn.2015-09.com.node:tgt1/192.168.221.130,3260,1:總用量 4-rw-------. 1 root root 2045 9月  22 23:50 default

6.要登入就用下面的命令來串連一台LUN到我們本地系統中,這會與伺服器驗證並允許我們登入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名字
--login :登陸

warning:
登出使用登入命令並在命令的最後使用logout來替換

[[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.登陸後,顯示特定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 = 0iface.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.接著列出使用的磁碟,fdisk會列出所有的登入認證過的磁碟 

[[email protected] ~]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00074c40   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1        2040    16384000   83  Linux/dev/sda2            2040        2611     4586496   82  Linux swap / SolarisDisk /dev/sdb: 5368 MB, 5368709120 bytes166 heads, 62 sectors/track, 1018 cylindersUnits = cylinders of 10292 * 512 = 5269504 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/sdc: 5368 MB, 5368709120 bytes166 heads, 62 sectors/track, 1018 cylindersUnits = cylinders of 10292 * 512 = 5269504 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/sdd: 5368 MB, 5368709120 bytes166 heads, 62 sectors/track, 1018 cylindersUnits = cylinders of 10292 * 512 = 5269504 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/sde: 4294 MB, 4294967296 bytes133 heads, 62 sectors/track, 1017 cylindersUnits = cylinders of 8246 * 512 = 4221952 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000

9.運行fdisk命令來建立一個新的分區,在使用fdisk建立新分區之後,我們無需重啟,就像使用我們本地的檔案系統一樣就行。因為這個將遠程共用儲存掛載到本地了。

[[email protected] ~]#  fdisk -cu /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x58426cdd.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): 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 for help): pDisk /dev/sdb: 5368 MB, 5368709120 bytes166 heads, 62 sectors/track, 1018 cylinders, total 10485760 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x58426cdd   Device Boot      Start         End      Blocks   Id  System/dev/sdb1            2048    10485759     5241856   83  LinuxCommand (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.

為所欲為的格式化新建立的分區

[[email protected] ~]#  mkfs.ext4 /dev/sdb1mke2fs 1.41.12 (17-May-2010)檔案系統標籤=作業系統:Linux塊大小=4096 (log=2)分塊大小=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks327680 inodes, 1310464 blocks65523 blocks (5.00%) reserved for the super user第一個資料區塊=0Maximum filesystem blocks=134217728040 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736正在寫入inode表: 完成                            Creating journal (32768 blocks): 完成Writing superblocks and filesystem accounting information: 完成This filesystem will be automatically checked every 25 mounts or180 days, whichever comes first.  Use tune2fs -c or -i to override.

10. 建立一個目錄來掛載新建立的分區

[[email protected] ~]# mkdir /mnt/iscsi[[email protected] ~]# mount /dev/sdb1 /mnt/iscsi/

   [[email protected] ~]# ls -l /mnt/iscsi/
   總用量 16
   drwx------. 2 root root 16384 9月 23 00:38 lost+found

讓我們看看掛載點

[[email protected] ~]# df -Th   //-T 輸出檔案系統類別型   -h以宜讀的方式顯示大小Filesystem     Type   Size  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

要想永久掛載麼,當然得東fsab的刀子

[[email protected] ~]# vim /etc/fstab [[email protected] ~]# cat /etc/fstab ## /etc/fstab# Created by anaconda on Tue Sep 22 20:53:15 2015## Accessible filesystems, by reference, are maintained under ‘/dev/disk‘# See man 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,說明這是一個網路裝置。

檢查我們fstab檔案是否有錯誤。

[[email protected] ~]# mount -av    //-a 所有掛載點 -v冗餘模式mount: tmpfs already mounted on /dev/shmmount: devpts already mounted on /dev/ptsmount: sysfs already mounted on /sysmount: proc already mounted on /procmount: /dev/sdb1 already mounted on /mnt/iscsinothing was mounted

beautiful,盡情使用吧。。。。。

 

 

參考資料

 

 

linux中國:https://linux.cn/   我最喜歡的linux中文網站

使用iSCSI Target建立集中式安全儲存(一):https://linux.cn/article-4971-1.html

鳥哥的LINUX私房菜--伺服器架設篇

 

CentOS iSCSI伺服器搭建------Initiator篇

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.