// 安装相关软件,其中kmod-xfs、xfsprogs为xfs文件系统的组件。

yum install binutils iscsi-initiator-utils kmod-xfs xfsprogs

//启动iscsi服务

service iscsi start

//查看存储服务器的iscsi是否在线

iscsiadm -m discovery --type sendtargets --portal 192.168.2.30

如下是输入上面的命令后返回的结果:
192.168.2.30:3260,1 iqn.1986-03.com.ibm:2145.v37001.node2

//设置开机自动登陆iscsi

iscsiadm -m node -T iqn.1986-03.com.ibm:2145.v37001.node2 -p 192.168.2.30:3260 --op update -n node.startup -v automatic

//显示当前的连接

iscsiadm -m session

如下是输入上面的命令后返回的结果:
tcp: [1] 192.168.2.30:3260,1 iqn.1986-03.com.ibm:2145.v37001.node2 (non-flash)

//查看存储空间是否已经显示在磁盘列表中

fdisk -l

如下显示了我存储的空间
Disk /dev/sdb: 32985.3 GB, 32985348833280 bytes, 64424509440 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 32768 bytes / 32768 bytes
Disk label type: gpt

//用parted命令进行分区

parted /dev/sdb          
mklabel gpt                     //创建标识
mkpart primary 0% 100%          //分配所有空间
print                           //显示当前分区
quit                            //退出

//用mkfs.ext4命令格式化硬盘

mkfs.ext4 -T largefile /dev/sdb1
参数说明:-T largefile对格式化大文件速度要快很多

如下是输入上面的命令后返回的输出:
[root@localhost ~]# mkfs.ext4 -T largefile /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=8 blocks, Stripe width=8 blocks
31457280 inodes, 8053063168 blocks
402653158 blocks (5.00%) reserved for the super user
First data block=0
245760 block groups
32768 blocks per group, 32768 fragments per group
128 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848, 512000000, 550731776, 644972544, 1934917632,
2560000000, 3855122432, 5804752896

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

//挂载

mount /dev/sdb1 /iscsi/

开机自动挂载

编辑/etc/fstab文件,加入如下代码:

UUID=bdef610b-0f6c-4888-b3ea-7dc986109604 /iscsi ext4 defaults,_netdev 0 0 
注意:一定要加_netdev不然系统会无法启动,_netdev的意思是等有了网络之后再挂载。