targetd服务端再添加4块硬盘:
创建RAID5并设置1块备份故障盘:
mdadm -Cv /dev/md0 -n 3 -l 5 -x 1 /dev/sd{b,c,d,e}
创建RAID阵列配置文件:
mdadm -Ds > /etc/mdadm.conf
vim /etc/mdadm.conf
DEVICE /dev/sdb /dev/sdc /dev/sdd /dev/sde
ARRAY /dev/md0 metadata=1.2 spares=2 name=localhost.localdomain:0 UUID=5d5e7663:aa6e6ba2:0ece43d3:6b4c14d2
安装targetd和targetcli工具包
yum install -y targetd targetcli
启动服务
systemctl start targetd
systemctl enable targetd
创建存储对象。
targetcli
查看当前的存储目录树:
/> ls
进入/backstores/block目录中:
/> cd /backstores/block
使用/dev/md0创建设备disk0:
/backstores/block> create disk0 /dev/md0
进入到iscsi目录中:
/> cd /iscsi
创建iSCSI target目标:
/iscsi> create iqn.2017-08.domain.com:target01
进入luns目录创建设备信息
/iscsi> cd iqn.2017-08.domain.com:target01/tpg1/luns
/iscsi/iqn.20...t01/tpg1/luns> create /backstores/block/disk0
/iscsi/iqn.20...t01/tpg1/luns> ls
o- luns ...... [LUNs: 1]
o- lun0 ...... [block/disk0 (/dev/md0)]
进入portals目录创建访问IP和端口
/iscsi/iqn.20...t01/tpg1/luns> cd ../portals/
/iscsi/iqn.20.../tpg1/portals> ls
o- portals ...... [Portals: 1]
o- 0.0.0.0:3260 ...... [OK]
/iscsi/iqn.20.../tpg1/portals> delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/iscsi/iqn.20.../tpg1/portals> create 192.168.200.100 3260
进入acls目录创建客户端访问控制
/iscsi/iqn.20.../tpg1/portals> cd ../acls
/iscsi/iqn.20...t01/tpg1/acls> ls
o- acls ....... [ACLs: 0]
/iscsi/iqn.20...t01/tpg1/acls> create iqn.2017-08.domain.com:webserver01
/iscsi/iqn.20...t01/tpg1/acls> create iqn.2017-08.domain.com:webserver02
进入根目录显示所有信息
/> cd /
/> ls
o- / ............................................................... [...]
o- backstores .................................................... [...]
| o- block ........................................ [Storage Objects: 1]
| | o- disk0 ................. [/dev/md0 (16.0GiB) write-thru activated]
| o- fileio ....................................... [Storage Objects: 0]
| o- pscsi ........................................ [Storage Objects: 0]
| o- ramdisk ...................................... [Storage Objects: 0]
o- iscsi .................................................. [Targets: 1]
| o- iqn.2017-08.domain.com:target01 ......................... [TPGs: 1]
| o- tpg1 ..................................... [no-gen-acls, no-auth]
| o- acls ................................................ [ACLs: 2]
| | o- iqn.2017-08.domain.com:webserver01 ......... [Mapped LUNs: 1]
| | | o- mapped_lun0 ....................... [lun0 block/disk0 (rw)]
| | o- iqn.2017-08.domain.com:webserver02 ......... [Mapped LUNs: 1]
| | o- mapped_lun0 ....................... [lun0 block/disk0 (rw)]
| o- luns ................................................ [LUNs: 1]
| | o- lun0 ............................... [block/disk0 (/dev/md0)]
| o- portals .......................................... [Portals: 1]
| o- 192.168.200.100:3260 ................................... [OK]
o- loopback ............................................... [Targets: 0]
/> saveconfig
/> exit
ss -ntlu | grep 3260
tcp LISTEN 0 256 192.168.200.100:3260
iSCSI Initiator客户端配置
- 安装iscsi-initiator-utils软件包
yum install -y iscsi-initiator-utils
2. 编辑iSCSI Initiator客户端名称文件(名称与ISCSI服务端的acls匹配)
vim /etc/iscsi/initiatorname.iscsi
#webserver01:
InitiatorName=iqn.2017-08.domain.com:webserver01
#webserver02:
InitiatorName=iqn.2017-08.domain.com:webserver02
3. 启动服务
systemctl restart iscsid.service
systemctl enable iscsid.service
4. iSCSI Initiator客户端发现和连接Target端存储设备
iscsiadm --mode discovery --type sendtargets --portal 192.168.200.100
192.168.200.100:3260,1 iqn.2017-08.domain.com:target01
iscsiadm --mode node --targetname iqn.2017-08.domain.com:target01 --portal 192.168.200.100:3260 --login
iscsiadm
--mode discovery 或-m discovery“表示发现查找
--type sendtargets或-t sendtargets或-t st”表示发布的target
--portal ip:port或-p ip:port用来指定服务器IP地址
--mode node或-m node表示管理目标节点
--login或-l表示登录连接
--logout表示登出连接
5. 多出来一块硬盘/dev/sdb
fdisk -l
6. 创建文件系统并挂载
mkfs.xfs -f /dev/sdb
mkdir /mnt/iscsi-disk01
mount /dev/sdb /mnt/iscsi-disk01/
7. 配置自动挂载
vim /etc/fstab
/dev/sdb /mnt/iscsi-disk01 xfs defaults,_netdev 0 0
设置为开机后自动挂载时因为iSCSI服务程序基于IP网络传输数据,所以我们必需在fstab文件中添加参数_netdev,代表网络联通后再挂载
df -h | grep /dev/sdb
/dev/sdb 16G 33M 16G 1% /mnt/iscsi-disk01
创建文件测试
touch 1 2 3 4
ll
total 0
-rw-r--r-- 1 root root 0 Aug 13 21:08 1
-rw-r--r-- 1 root root 0 Aug 13 21:08 2
-rw-r--r-- 1 root root 0 Aug 13 21:08 3
-rw-r--r-- 1 root root 0 Aug 13 21:08 4
umount /dev/sdb
webserver02挂载
mount /dev/sdb /mnt/iscsi-disk01
ls
1 2 3 4