服务器信息:

[root@initiator ~]# cat /etc/redhat-release
CentOS release 6.6 (Final)
[root@initiator ~]# uname -a
Linux 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
[root@initiator ~]# ifconfig
eth0 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才行。开始上菜。。。

[root@initiator ~]#  yum search all iscsi
已加载插件:fastestmirror
Loading 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 programs
iscsi-initiator-utils-devel.x86_64 : Development files for iscsi-initiator-utils
gpxe-bootimgs.noarch : Network boot loader images in bootable USB, CD, floppy and GRUB formats
gpxe-roms.noarch : Network boot loader roms in .rom format
gpxe-roms-qemu.noarch : Network boot loader roms supported by QEMU, .rom format
isns-utils.x86_64 : The iSNS daemon and utility programs
scsi-target-utils.x86_64 : The SCSI target daemon and utility programs

1.yum大法安装

[root@initiator ~]# yum install iscsi-initiator-utils iscsi-initiator-utils-devel -y

2.启动服务开机启动

[root@initiator ~]# service iscsid start
正在启动 iscsid: [确定]
[root@initiator ~]# chkconfig iscsi on
[root@initiator ~]# 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)。

[root@initiator ~]# iscsiadm --mode discoverydb --type sendtargets --portal 192.168.221.130 --discover
192.168.221.130:3260,1 iqn.2015-09.com.node:tgt1

--mode discoverydb:使用检测的方式进行iscsiadmin命令功能

--type sendtargets :通过iSCSI的协议,检测后面的设备所拥有的target数据

--portal                 :就是那台iSCSI设备的IP与端口,不写端口的默认是3260

OK。摸摸哒。找到了。

显示出目前系统上面所有的target数据,可能并未登陆:

[root@initiator ~]# iscsiadm -m node
192.168.221.130:3260,1 iqn.2015-09.com.node:tgt1

默认配置都在defaults文件中

[root@initiator ~]# ll -R /var/lib/iscsi/nodes/
/var/lib/iscsi/nodes/:
总用量 4
drw-------. 3 root root 4096 9月 22 23:50 iqn.2015-09.com.node:tgt1 /var/lib/iscsi/nodes/iqn.2015-09.com.node:tgt1:
总用量 4
drw-------. 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。

[root@initiator ~]# iscsiadm --mode node --targetname iqn.2015-09.com.node:tgt1 --portal 192.168.221.130:3260 --login
Logging 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来替换

[root@initiator ~]# 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的所有数据

[root@initiator ~]# iscsiadm --mode node --targetname iqn.2015-09.com.node:tgt1 --portal 192.168.221.130:3260
# BEGIN RECORD 6.2.0-873.13.el6
node.name = iqn.2015-09.com.node:tgt1
node.tpgt = 1
node.startup = automatic
node.leading_login = No
iface.hwaddress = <empty>
iface.ipaddress = <empty>
iface.iscsi_ifacename = default
iface.net_ifacename = <empty>
iface.transport_name = tcp
iface.initiatorname = <empty>
iface.state = <empty>
iface.vlan_id = 0
iface.vlan_priority = 0
iface.vlan_state = <empty>
iface.iface_num = 0
iface.mtu = 0
iface.port = 0
iface.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 = 0
iface.ttl = 0
........................

8.接着列出使用的磁盘,fdisk会列出所有的登录认证过的磁盘 

[root@initiator ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00074c40 Device Boot Start End Blocks Id System
/dev/sda1 * 1 2040 16384000 83 Linux
/dev/sda2 2040 2611 4586496 82 Linux swap / Solaris Disk /dev/sdb: 5368 MB, 5368709120 bytes
166 heads, 62 sectors/track, 1018 cylinders
Units = cylinders of 10292 * 512 = 5269504 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000 Disk /dev/sdc: 5368 MB, 5368709120 bytes
166 heads, 62 sectors/track, 1018 cylinders
Units = cylinders of 10292 * 512 = 5269504 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000 Disk /dev/sdd: 5368 MB, 5368709120 bytes
166 heads, 62 sectors/track, 1018 cylinders
Units = cylinders of 10292 * 512 = 5269504 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000 Disk /dev/sde: 4294 MB, 4294967296 bytes
133 heads, 62 sectors/track, 1017 cylinders
Units = cylinders of 8246 * 512 = 4221952 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

9.运行fdisk命令来创建一个新的分区,在使用fdisk创建新分区之后,我们无需重启,就像使用我们本地的文件系统一样就行。因为这个将远程共享存储挂载到本地了。

[root@initiator ~]#  fdisk -cu /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building 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): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-10485759, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759):
Using default value 10485759 Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 83 Command (m for help): p Disk /dev/sdb: 5368 MB, 5368709120 bytes
166 heads, 62 sectors/track, 1018 cylinders, total 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x58426cdd Device Boot Start End Blocks Id System
/dev/sdb1 2048 10485759 5241856 83 Linux Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.

为所欲为的格式化新创建的分区

[root@initiator ~]#  mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310464 blocks
65523 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock 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 or
180 days, whichever comes first. Use tune2fs -c or -i to override.

10. 创建一个目录来挂载新创建的分区

[root@initiator ~]# mkdir /mnt/iscsi
[root@initiator ~]# mount /dev/sdb1 /mnt/iscsi/

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

让我们看看挂载点

[root@initiator ~]# 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的刀子

[root@initiator ~]# vim /etc/fstab
[root@initiator ~]# 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 1
UUID=1766dc2c-509e-4547-b647-ec42e61e9223 swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/sdb1 /mnt/iscsi ext4 defaults,_netdev 0 0

_netdev,说明这是一个网络设备。

检查我们fstab文件是否有错误。

[root@initiator ~]# mount -av    //-a 所有挂载点 -v冗余模式
mount: tmpfs already mounted on /dev/shm
mount: devpts already mounted on /dev/pts
mount: sysfs already mounted on /sys
mount: proc already mounted on /proc
mount: /dev/sdb1 already mounted on /mnt/iscsi
nothing was mounted

beautiful,尽情使用吧。。。。。

参考资料

linux中国:https://linux.cn/   我最喜欢的linux中文网站

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

鸟哥的LINUX私房菜--服务器架设篇

 

CentOS iSCSI服务器搭建------Initiator篇的更多相关文章

  1. CentOS iSCSI服务器搭建------Target篇

    先上服务器信息(当然是我YY的服务器.哈哈) [root@node ~]# cat /etc/redhat-release CentOS release 6.6 (Final) [root@node ...

  2. CentOS iSCSI服务器搭建------LUN篇

    先上服务器信息(你懂得) [root@node ~]# cat /etc/redhat-release CentOS release 6.6 (Final) [root@node ~]# uname ...

  3. Centos vsftpd服务器搭建

    Centos vsftpd服务器搭建 时间:2016-07-18 1.最为简单的vsftpd服务器搭建 1.安装vsftpd 1.yum 安装 yum install vsftpd 2.rpm文件安装 ...

  4. centos dhcp 服务器搭建 多vlan

    centos dhcp 服务器搭建   多vlan centos 6.5   版本     /etc/dhcp/dhcpd.conf         服务器配置文件 /etc/rc.d/init.d/ ...

  5. iSCSI 服务器搭建

    一.简介 SCSI(Small Computer System Interface),小型计算机系统接口,是一种用于计算机及其周边设备之间(硬盘.软驱.光驱.打印机.扫描仪等)系统级接口的独立处理器标 ...

  6. centos svn服务器搭建

    1.安装svnyum install subversion查看安装目录rpm -ql subversion 查看yum安装subversion的位置 2.创建仓库创建版本库目录mkdir -p /va ...

  7. CentOS SVN 服务器搭建

    源码目录:/home/user/project 工程名:project 工程目录:/source/svn/project 访问地址:svn://ip/project 一. 安装svn yum inst ...

  8. linux centos ftp服务器搭建

    原文参考 步骤一:构建vsftpd服务器 1)使用yum安装vsftpd软件包yum -y install vsftpdrpm -q vsftpd #确认安装成功,显示vsftpd对应版本 vsftp ...

  9. Centos 7服务器搭建MySQL(mariadb)服务

    1.下载并安装MySQL yum install mariadb mariadb-server -y 2.启动MySQL systemctl start mariadb 3.对mariadb进行初始化 ...

随机推荐

  1. How to Handle Exception

  2. STL学习笔记(string)

    动机 C++标准程序库中的string class使我们可以将string当做一个一般型别.我们可以像对待基本型别那样地复制.赋值和比较string, 再也不必但系内存是否足够.占用的内存实际长度等问 ...

  3. 设计模式之十一:抽象工厂模式(Abstract Factory)

    抽象工厂模式: 提供了一个创建一系列相关的或相互依赖的对象的接口而不须要详细指定它们的类型. Provide an interface for creating families of related ...

  4. 转 SQL行转列汇总

    1.PIVOT 用于将列值旋转为列名(即行转列) PIVOT 的一般语法是:PIVOT(聚合函数(列名) FOR 列名 in (列值1,…) )AS P select * from TB pivot ...

  5. shell 判断问题总结

    #!/bin/bash #比如需要判断一个变量是否含有值: if [[ -z $1 ]] ; thenecho "Something like empty!"exit 0;fi # ...

  6. 【0】按照Django官网:实现第一个django app 安装必要的工具/模块

    1.环境配置: (1)Install Setuptools¶ To install Python packages on your computer, Setuptools is needed. Do ...

  7. Atitit.pdf 预览 转换html attilax总结

    Atitit.pdf 预览 转换html attilax总结 1. Swf flash还是html1 2. pdf2htmlEX1 3. iText 5.5.0 发布,Java 的 PDF 操作类库1 ...

  8. 挖一挖C#中那些我们不经常使用的东西之系列(4)——GetHashCode,ExpandoObject

    一:GetHashCode 从MSDN上能够看到的解释是:用作特定类型的哈希函数,也就是说不论什么对象的实例都会有一个int32类型的HashCode.而且存放在FCL中的 HashCollectio ...

  9. SendMessage用法

    SendMessage(hWnd,wMsg,wParam,lParam) 参数1:hWnd-窗口句柄.窗口可以是任何类型的屏幕对象. 参数2:wMsg-用于区别其他消息的常量值. 参数3:wParam ...

  10. 什么是CouchDB?

    ※本文对CouchDB的解释是来自Apache CouchDB的官网的译文,如果有什么问题,请指正. 1.CouchDB简介 CouchDB是一种利用JSON文件,javascript作为MapRed ...