环境RHEL7.4
1.搭建服务器端主机环境
网络配置
网卡eth0 10.0.0.1
网卡eth1 10.1.0.1
网卡eth2 10.2.0.1
网卡eth3 10.3.0.1
硬盘配置
添加一块100GB硬盘,配置成DATAVG,划分LV并发布成iscsi硬盘
iscsi target服务配置
#yum install targetd targetcli -y
启动服务,并设定为开机启动
systemctl enable target
systemctl start target
开启防火墙端口
firewall-cmd --permanent --add-port=3260/tcp
firewall-cmd --reload
这里使用新添加的/dev/sdb作为存储盘
创建分区1,pv,vg,lv
fdisk /dev/sdb
p查看->n新建->p主分区->1分区1->回车默认起始扇区->回车默认使用全部大小
t选择分区类型->L列出所有类型->8e设定为Linux LVM->w写入磁盘
# partprobe /dev/sdb
# partprobe /dev/sdb
# pvcreate /dev/sdb1
# vgcreate vgiscsi00 /dev/sdb1
# lvcreate -n lv_5G_00 -L 5G vgiscsi00
# lvcreate -n lv_5G_01 -L 5G vgiscsi00
# lvcreate -n lv_5G_02 -L 5G vgiscsi00
创建disk
/>cd backstores/block
/backstores/block> create asmdisk5G00.disk /dev/vgiscsi00/lv_5G_00
/backstores/block> create asmdisk5G01.disk /dev/vgiscsi00/lv_5G_01
/backstores/block> create asmdisk5G02.disk /dev/vgiscsi00/lv_5G_02
创建iscsi target目标并分配创建LUN
/backstores/block> cd /iscsi/
/iscsi> create iqn.2015-06.com.sample.domain:sharedisk
为客户端节点创建acl
create iqn.2015-06.com.sample.domain:server00
为目标创建LUN
create /backstores/block/asmdisk5G00.disk
create /backstores/block/asmdisk5G01.disk
create /backstores/block/asmdisk5G02.disk
配置门户以使用目标侦听192.168.31.11端口3260
create 10.0.0.1
create 10.1.0.1
create 10.2.0.1
create 10.3.0.1
保存配置
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
2.客户端主机配置
网卡eth0 10.0.0.10
网卡eth1 10.1.0.11
网卡eth2 10.2.0.12
网卡eth3 10.3.0.13
客户端访问iscsi存储
1. 安装软件包
yum install iscsi-initiator-utils -y
2. 设定initiator名称
[[email protected] ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2015-06.com.sample.domain:server00
3. 启动服务,并开机启动
systemctl enable iscsi
systemctl start iscsi
4. 发现目标服务器门户
# iscsiadm -m discovery -t st -p 10.0.0.1
5.登陆到呈现的iSCSI目标
# iscsiadm -m node -T iqn.2015-06.com.sample.domain:sharedisk -p 10.0.0.1 –l
# iscsiadm -m node -T iqn.2015-06.com.sample.domain:sharedisk -p 10.1.0.1 –l
# iscsiadm -m node -T iqn.2015-06.com.sample.domain:sharedisk -p 10.2.0.1 –l
# iscsiadm -m node -T iqn.2015-06.com.sample.domain:sharedisk -p 10.3.0.1 -l
2. 标示由iSCSI目标登陆所创建的最新可用块设备
lsblk
tail /var/log/messages
3. 列出iscsi 服务所识别的目标
iscsiadm -m session -P 3
4. 验证iSCSI磁盘的设备节点
[[email protected] nodes]# iscsiadm -m session -P 3|grep Attached
5. 查找新iSCSI目标的持久节点记录
cd /var/lib/iscsi/nodes
ls -1R
6. 查看链接参数默认值
less iqn.2015-06.com.sample.domain:sharedisk /10.0.0.1,3260,1/default
7. 断开链接
# iscsiadm -m node -T iqn.2015-06.com.sample.domain:sharedisk -p 10.0.0.1 –u
# iscsiadm -m node -T iqn.2015-06.com.sample.domain:sharedisk -p 10.1.0.1 –u
# iscsiadm -m node -T iqn.2015-06.com.sample.domain:sharedisk -p 10.2.0.1 –u
# iscsiadm -m node -T iqn.2015-06.com.sample.domain:sharedisk -p 10.3.0.1 -u
ls -1R仍存在记录,但是lsblk块存储消失,重启iscsi服务,lsblk重新发现
8. 彻底删除链接
# iscsiadm -m node -T iqn.2015-06.com.sample.domain:sharedisk -p 10.0.0.1 -u
# iscsiadm -m node -T iqn.2015-06.com.sample.domain:sharedisk -p 10.1.0.1 -u
# iscsiadm -m node -T iqn.2015-06.com.sample.domain:sharedisk -p 10.2.0.1 -u
# iscsiadm -m node -T iqn.2015-06.com.sample.domain:sharedisk -p 10.3.0.1 -u
# iscsiadm -m node -T iqn.2015-06.com.sample.domain:sharedisk -p 10.0.0.1 -o delete
# iscsiadm -m node -T iqn.2015-06.com.sample.domain:sharedisk -p 10.1.0.1 -o delete
# iscsiadm -m node -T iqn.2015-06.com.sample.domain:sharedisk -p 10.2.0.1 -o delete
# iscsiadm -m node -T iqn.2015-06.com.sample.domain:sharedisk -p 10.3.0.1 -o delete
ls -1R记录消失,但是lsblk块存储消失,重启iscsi服务,lsblk没有节点记录
9. 重新发现目标门户,节点记录自动创建
# iscsiadm -m discovery -t st -p 192.168.31.11
#ls -1R
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 29.5G 0 part
├─rhel-root 253:0 0 27.5G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
sr0 11:0 1 3.5G 0 rom
10. 使用iscsi磁盘
[[email protected] nodes]# blkid /dev/sdb
[[email protected] nodes]# fdisk -l
原文地址:https://www.cnblogs.com/ooflyoo/p/9035730.html