iscsi的基本用法
############iscsi######
在server端
1.创建lvm逻辑卷
[[email protected] ~]# pvcreate /dev/vdb1Physical volume "/dev/vdb1" successfully created
[[email protected] ~]# vgcreate vg0 /dev/vdb1
Volume group "vg0" successfully created
[[email protected] ~]# lvcreate -l 249 -n iscsi_storage vg0
Logical volume "iscsi_storage" created
[ro[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
iscsi_storage vg0 -wi-a----- 996.00m
[[email protected] ~]#
2.配置服务
[[email protected] ~]# yum install targetcli -y[[email protected] ~]# systemctl enable target.service
ln -s '/usr/lib/systemd/system/target.service' '/etc/systemd/system/multi-user.target.wants/target.service'
[[email protected] ~]# targetcli ##进入该服务,进行编辑配置
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb34
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> ls
/> /backstores/block create server6storage /dev/vg0/iscsi_storage ##给该硬件重命名,在该目录
Created block storage object server6storage using /dev/vg0/iscsi_storage.
/> /iscsi create iqn.2017-06.com.example:strage6 ##创建iqn
Created target iqn.2017-06.com.example:strage6.
Created TPG 1.
/> /iscsi/iqn.2017-06.com.example:strage6/tpg1/luns create /backstores/block/server6storage ##关联iqn和该硬件
Created LUN 0.
/> /iscsi/iqn.2017-06.com.example:strage6/tpg1/acls create iqn.2017-06.com.example:server6storage ##创建iqn的密码
Created Node ACL for iqn.2017-06.com.example:server6storage
Created mapped LUN 0.
/> /iscsi/iqn.2017-06.com.example:strage6/tpg1/portals create 172.25.6.11 ##开启该机器上的端口
Using default IP port 3260
Created network portal 172.25.6.11:3260.
/> exit ##退出保存
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[[email protected] ~]#
desktop端:
[[email protected] ~]# vim /etc/iscsi/initiatorname.iscsi ##编辑配置文件输入密码[[email protected] ~]# systemctl restart iscsi
[[email protected] ~]# iscsiadm -m discovery -t st -p 172.25.6.11
172.25.6.11:3260,1 iqn.2017-06.com.example:strage6
[[email protected] ~]# iscsiadm -m node -T iqn.2017-06.com.example:strage6 -p 172.25.6.11 -l ##登陆iscsi服务
Logging in to [iface: default, target: iqn.2017-06.com.example:strage6, portal: 172.25.6.11,3260] (multiple)
Login to [iface: default, target: iqn.2017-06.com.example:strage6, portal: 172.25.6.11,3260] successful.
[[email protected] ~]# yum install tree -y
[[email protected] ~]# tree -C /var/lib/iscsi/
3.挂载
mkfs.xfs /dev/sdamount /dev/sda /mnt
[[email protected] ~]# blkid
[[email protected] ~]# vim /etc/fstab
UUID="" /mnt xfs defaults,_netdev 0 0 ##_netdev先开启网络服务
4.删除
客户端:[[email protected] ~]# umount /mnt
[[email protected] ~]# vim /etc/fstab
[[email protected] ~]# iscsiadm -m node -T iqn.2017-06.com.example:strage6 -p 172.25.6.11 -u ##客户端退出iscsi服务
Logging out of session [sid: 1, target: iqn.2017-06.com.example:strage6, portal: 172.25.6.11,3260]
Logout of [sid: 1, target: iqn.2017-06.com.example:strage6, portal: 172.25.6.11,3260] successful.
[[email protected] ~]# iscsiadm -m node -T iqn.2017-06.com.example:strage6 -p 172.25.6.11 -o delete ##删除iscsi的配置文件
服务端:
/> clearconfig confirm=True ##清除iscsi的所有配置信息
All configuration cleared
/>