发布iSCSI网络磁盘
1.1 问题
本例要求配置 server0 提供 iSCSI 服务,要求如下:
磁盘名为iqn.2016-02.com.example:server0
服务端口为 3260
使用 iscsi_store 作其后端卷,其大小为 3GiB
此磁盘服务只能被 desktop0.example.com 访问
1.2 步骤
步骤一:准备磁盘空间,划分分区
1)利用parted命令划分/dev/vdb
[root@server0 /]# parted /dev/vdb
(parted) mktable gpt //指定分区模式为gpt
(parted) mkpart primary ext4 0 3GiB
警告: The resulting partition is not properly aligned for best performance.
忽略/Ignore/放弃/Cancel? Ignore
(parted) print
……
Number Start End Size File system Name 标志
1 17.4kB 3221MB 3221MB primary
(parted) quit
2)命令行查看分区信息
[root@server0 /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
……
└─vdb1 252:17 0 3G 0 part ln -s
3)查看分区设备文件
[root@server0 /]# ls /dev/vdb1
/dev/vdb1
步骤二:安装和配置ISCSI磁盘
1)安装软件包targetcli
[root@server0 ~]# yum -y install targetcli
2)命令行运行targetcli配置ISCSI磁盘
[root@server0 /]# targetcli
/> backstores/block create iscsi_store /dev/vdb1 //创建后端存储
/> iscsi/ create iqn.2016-02.com.example:server0 //创建iqn对象
/> iscsi/iqn.2016-02.com.example:server0/tpg1/luns create /backstores/block/iscsi_store //将iqn对象与后端存储绑定
/> iscsi/iqn.2016-02.com.example:server0/tpg1/acls create iqn.2016-02.com.example:desktop0 //设置客户端的iqn
/> iscsi/iqn.2016-02.com.example:server0/tpg1/portals/ create 0.0.0.0 3260 //开启本地监听的IP地址与端口
/> exit
3)启动target服务,并设置开机自启动
[root@server0 /]# systemctl restart target
[root@server0 /]# systemctl enable target
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.