iscsi的基本用法

来源:互联网 发布:软件健壮性 软件可靠性 编辑:程序博客网 时间:2024/05/22 15:28

############iscsi######

在server端

1.创建lvm逻辑卷

[root@server6 ~]# pvcreate /dev/vdb1
  Physical volume "/dev/vdb1" successfully created
[root@server6 ~]# vgcreate vg0 /dev/vdb1
  Volume group "vg0" successfully created
[root@server6 ~]# lvcreate -l 249 -n iscsi_storage vg0
  Logical volume "iscsi_storage" created
[root@server6 ~]# lvs
  LV            VG   Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  iscsi_storage vg0  -wi-a----- 996.00m                                             

[root@server6 ~]#


2.配置服务

[root@server6 ~]# yum install targetcli -y
[root@server6 ~]# systemctl enable target.service
ln -s '/usr/lib/systemd/system/target.service' '/etc/systemd/system/multi-user.target.wants/target.service'
[root@server6 ~]# 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

[root@server6 ~]#




desktop端:
[root@desktop6 ~]# vim /etc/iscsi/initiatorname.iscsi ##编辑配置文件输入密码
[root@desktop6 ~]# systemctl restart iscsi
[root@desktop6 ~]# iscsiadm -m discovery -t st -p 172.25.6.11
172.25.6.11:3260,1 iqn.2017-06.com.example:strage6
[root@desktop6 ~]# 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.
[root@desktop6 ~]# yum install tree -y

[root@desktop6 ~]# tree -C /var/lib/iscsi/


[root@desktop6 ~]# fdisk -l


3.挂载

mkfs.xfs /dev/sda
mount /dev/sda /mnt
[root@desktop6 ~]# blkid
[root@desktop6 ~]# vim /etc/fstab
UUID=""    /mnt xfs defaults,_netdev    0 0    ##_netdev先开启网络服务

4.删除

客户端:
[root@desktop6 ~]# umount /mnt
[root@desktop6 ~]# vim /etc/fstab
[root@desktop6 ~]# 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.
[root@desktop6 ~]# 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

/>



原创粉丝点击