RHEL7学习之ISCSI配置
ISCSI服务器:192.168.10.10
ISCSI客户端:192.168.10.20
在ISCSI服务器添加两块硬盘:/dev/sdb /de/sdc
一,在服务端安装
[root@localhost ~]# yum install targetd targetcli
二,配置服务端
1,创建块设备
[root@localhost ~]# 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 o- / ......................................................................................................................... [...] o- backstores .............................................................................................................. [...] | o- block .................................................................................................. [Storage Objects: 0] | o- fileio ................................................................................................. [Storage Objects: 0] | o- pscsi .................................................................................................. [Storage Objects: 0] | o- ramdisk ................................................................................................ [Storage Objects: 0] o- iscsi ............................................................................................................ [Targets: 0] o- loopback ......................................................................................................... [Targets: 0] /> cd backstores/block /backstores/block> create disk0 /dev/sdb Created block storage object disk0 using /dev/sdb. /backstores/block> create disk1 /dev/sdc Created block storage object disk1 using /dev/sdc.
2,创建target目标
/> cd iscsi /iscsi> create iqn.2016-02.xyz.abc:identifier Created target iqn.2016-02.xyz.abc:identifier. Created TPG 1.
3,创建LUN
/iscsi> cd iqn.2016-02.xyz.abc:identifier/tpg1/luns /iscsi/iqn.20...ier/tpg1/luns> create /backstores/block/disk0 Created LUN 0. /iscsi/iqn.20...ier/tpg1/luns> create /backstores/block/disk1 Created LUN 1.
4,创建ACL
/iscsi/iqn.20...ier/tpg1/acls> create iqn.2016-02.xyz.abc:identifier Created Node ACL for iqn.2016-02.xyz.abc:identifier Created mapped LUN 1. Created mapped LUN 0.
/iscsi/iqn.20.../tpg1/portals> create 192.168.10.10 Using default IP port 3260 Created network portal 192.168.10.10:3260.
5,exit保存退出
/> ls o- / ......................................................................................................................... [...] o- backstores .............................................................................................................. [...] | o- block .................................................................................................. [Storage Objects: 2] | | o- disk0 ............................................................................ [/dev/sdb (2.0GiB) write-thru activated] | | o- disk1 ............................................................................ [/dev/sdc (2.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.2016-02.xyz.abc:identifier .................................................................................... [TPGs: 1] | o- tpg1 ............................................................................................... [no-gen-acls, no-auth] | o- acls .......................................................................................................... [ACLs: 1] | | o- iqn.2016-02.xyz.abc:identifier ....................................................................... [Mapped LUNs: 2] | | o- mapped_lun0 ................................................................................. [lun0 block/disk0 (rw)] | | o- mapped_lun1 ................................................................................. [lun1 block/disk1 (rw)] | o- luns .......................................................................................................... [LUNs: 2] | | o- lun0 ......................................................................................... [block/disk0 (/dev/sdb)] | | o- lun1 ......................................................................................... [block/disk1 (/dev/sdc)] | o- portals .................................................................................................... [Portals: 1] | o- 192.168.10.10:3260 ............................................................................................... [OK] o- loopback ......................................................................................................... [Targets: 0] /> exit Global pref auto_save_on_exit=true Last 10 configs saved in /etc/target/backup. Configuration saved to /etc/target/saveconfig.json
三,客户端配置
1,安装
[root@localhost ~]# yum install iscsi-initiator-utils
2,编辑配置文件
[root@localhost ~]# !v vim /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2016-02.xyz.abc:identifier
3,查看
[root@localhost ~]# iscsiadm -m discovery -t st -p 192.168.10.10 192.168.10.10:3260,1 iqn.2016-02.xyz.abc:identifier
4,使用
[root@localhost ~]# iscsiadm -m node -T iqn.2016-02.xyz.abc:identifier -p 192.168.10.10 --login Logging in to [iface: default, target: iqn.2016-02.xyz.abc:identifier, portal: 192.168.10.10,3260] (multiple) Login to [iface: default, target: iqn.2016-02.xyz.abc:identifier, portal: 192.168.10.10,3260] successful.
5,格式化
[root@localhost ~]# mkfs.xfs /dev/sdb
[root@localhost ~]# mkfs.xfs /dev/sdc
6,写入/etc/fstab
[root@localhost ~]# blkid | grep sdb /dev/sdb: UUID="c2b6b91a-7197-4e8b-90b3-ad8c09ff931f" TYPE="xfs" [root@localhost ~]# blkid | grep sdc /dev/sdc: UUID="8df58e2f-3105-4d2e-9a01-c7931af91a3e" TYPE="xfs" [root@localhost ~]# vim /etc/fstab/dev/mapper/rhel-root / xfs defaults 1 1 UUID=8d922f42-25a9-42aa-aee2-6e29b1ac7f1a /boot xfs defaults 1 2 /dev/mapper/rhel-swap swap swap defaults 0 0 /dev/cdrom /media/cdrom iso9660 defaults 0 0 UUID=c2b6b91a-7197-4e8b-90b3-ad8c09ff931f /iscsi1 xfs defaults,_netdev 0 0 UUID=8df58e2f-3105-4d2e-9a01-c7931af91a3e /iscsi2 xfs defaults,_netdev 0 0
7,挂载
[root@localhost ~]# mkdir /iscsi1 [root@localhost ~]# mkdir /iscsi2 [root@localhost ~]# mount -a [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-root 18G 940M 17G 6% / devtmpfs 484M 0 484M 0% /dev tmpfs 490M 0 490M 0% /dev/shm tmpfs 490M 6.7M 484M 2% /run tmpfs 490M 0 490M 0% /sys/fs/cgroup /dev/sr0 3.5G 3.5G 0 100% /media/cdrom /dev/sda1 497M 87M 411M 18% /boot /dev/sdb 2.0G 33M 2.0G 2% /iscsi1 /dev/sdc 2.0G 33M 2.0G 2% /iscsi2
iscsiadm的使用方法
查看服务器共享的设备
iscsiadm -m discovery -t st -p 192.168.10.10
显示已发现节点信息
iscsiadm -m node
登陆
iscsiadm -m node -T iqn.2016-2.xyz.abc:identifier -p 192.168.120.198 –l
登出
iscsiadm -m node -T iqn.2016-2.xyz.abc:identifier -p 192.168.120.198 -u
删除目标器节点信息:
iscsiadm -m node -o delete -T iqn.2016-2.xyz.abc:identifier -p 192.168.10.10