环境介绍:
IP SAN服务器1(202.1.1.10)
IP SAN 服务器2(202.1.1.30)
IP SAN 客户端 (202.1.1.20)
一、Linux系统实现 ISCSI 存储端(target)服务器1
(1)准备一块硬盘或一个分区:
[root@ipsan ~]# parted /dev/vdb p
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:
Number Start End Size File system 标志
1 0.00B 21.5GB 21.5GB xfs
(2) 安装包:
[root@ipsan ~]# yum -y install targetcli.noarch
(3) 定义target共享iqn:
[root@ipsan ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb41
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> /backstores/block create ipsan /dev/vdb
/> /iscsi create iqn.2019-04.com.uplook:ipsan1
/iscsi/iqn.2019-04.com.uplook:ipsan1/tpg1/luns create /backstores/block/ipsan
/> cd /iscsi/iqn.2019-04.com.uplook:ipsan1/tpg1/
/iscsi/iqn.20...k:ipsan1/tpg1> set attribute demo_mode_write_protect=0
/iscsi/iqn.20...k:ipsan1/tpg1> set attribute generate_node_acls=1
/iscsi/iqn.20...k:ipsan1/tpg1> set attribute cache_dynamic_acls=1
/iscsi/iqn.20...k:ipsan1/tpg1> cd /
/> saveconfig
(4). 启动服务
[root@ipsan ~]# systemctl start tgtd
[root@ipsan ~]# systemctl enable tgtd
[root@ipsan ~]# tgt-admin --show
[root@ipsan ~]# netstat -tnlp |grep :3260
tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN 15135/tgtd
tcp 0 0 :::3260 :::* LISTEN 15135/tgtd
5. 添加新的共享(当前有initiator端正在使用)
[root@ipsan ~]# tgt-admin --force --update ALL 新增强制更新
二、initiator端(使用存储的前端服务器)客户端
(1)安装包:
[root@ipsan2 ~]# yum -y install iscsi-*
(2) 发现存储:
[root@ipsan2 ~]# iscsiadm -m discovery -t st -p 202.1.1.10
202.1.1.10:3260,1 iqn.2019-04.com.uplook:ipsan1
(3) login登陆存储:
方法一:登入指定的存储
[root@ipsan2 ~]# iscsiadm -m node -T iqn.2019-04.com.uplook:ipsan1 -l
方法二:登入所有的(/var/lib/iscsi/)
[root@ipsan2 ~]# systemctl restart iscsi
(4) 挂载使用(可格式化)
mkfs.xfs /dev/sda
mkdir /sda
mount /dev/sda /sda/
df -h
三. Linux系统实现 ISCSI 存储端(target)服务器2
(1)准备一块硬盘或一个分区:
[root@ipsanserver2 opt]# parted /dev/vdb p
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 25.8GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name 标志
1 17.4kB 10.0GB 10000MB primary
(2) 装包:
[root@ipsanserver2 opt]# ls
perl-5.16.3-294.el7_6.x86_64.rpm
perl-Config-General-2.61-1.el7.noarch.rpm
perl-libs-5.16.3-294.el7_6.x86_64.rpm
perl-macros-5.16.3-294.el7_6.x86_64.rpm
perl-Pod-Escapes-1.04-294.el7_6.noarch.rpm
scsi-target-utils-1.0.55-4.el7.x86_64.rpm
[root@ipsanserver2 opt]# yum -y install *.rpm
(3) 修改配置文件:
[root@ipsanserver2 opt]# vim /etc/tgt/conf.d/sample.conf
9
10 backing-store /dev/vdb1
11 #initiator-address 202.1.1.100 # 访问控制
12
13
14 backing-store /dev/vdb2
15
[root@ipsanserver2 opt]# systemctl start tgtd.service
[root@ipsanserver2 opt]# tgt-admin -f --update ALL #新增强制更新
[root@ipsanserver2 opt]# tgt-admin --show | grep -i vdb
Backing store path: /dev/vdb1
Backing store path: /dev/vdb2
客户端操作同前
[root@ipsan2 iscsi]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/cl-root 17G 1.1G 16G 7% /
devtmpfs 910M 0 910M 0% /dev
tmpfs 920M 0 920M 0% /dev/shm
tmpfs 920M 8.4M 912M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
/dev/vda1 1014M 139M 876M 14% /boot
/dev/sr0 4.1G 4.1G 0 100% /mnt/centos7u3
tmpfs 184M 0 184M 0% /run/user/0
/dev/sdb 9.4G 33M 9.3G 1% /sdb
/dev/sda 9.4G 33M 9.3G 1% /sda
/dev/sdc 20G 33M 20G 1% /sdc