[日期:2015-04-12] | 来源:Linux社区 作者:linjohn |
RHCE7认证学习笔记34——配置ISCSI
一、存储设备类型
DSA:直接区域存储
NAS:网络区域存储
SAN:存储区域网络,块级别共享
二、配置iscsi服务器端
这里举例子说明,假如服务器有2个分区/dev/sdb7,/dev/sdb8要共享出去:
/dev/sdb7 1230848 1640447 200M Linux filesyste
/dev/sdb8 1640448 2459647 400M Linux filesyste
安装target包:
[root@linuxidc ~]# yum install target\* -y
启动target服务
[root@linuxidc ~]# systemctl start target
配置步骤:
1、准备要共享的块;
使用targetcli命令进入target配置界面:
[root@linuxidc ~]# targetcli
/> pwd
/
/> 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]
进入backstores/block目录创建要共享的块,创建block1和block2:
/> cd backstores/
/backstores> ls
o- backstores................................................................................................................[...]
o- block ....................................................................................................[Storage Objects: 0]
o- fileio...................................................................................................[Storage Objects: 0]
o- pscsi ....................................................................................................[Storage Objects: 0]
o- ramdisk..................................................................................................[Storage Objects: 0]
/backstores/block> create block1 dev=/dev/sdb7
Created block storage object block1 using /dev/sdb7.
/backstores/block> create block2 dev=/dev/sdb8
Created block storage object block2 using /dev/sdb8.
/backstores/block>ls
o- block......................................................................................................[Storage Objects: 2]
o- block1..........................................................................[/dev/sdb7 (200.0MiB) write-thru deactivated]
o- block2..........................................................................[/dev/sdb8 (400.0MiB) write-thru deactivated]
exit退出保存targetcli,并重新进入:
/backstores/block> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[root@linuxidc ~]# targetcli
2、创建一个target;
target标准名字格式:
年 月 域名倒写名字
iqn.2015-02.com.sg:disk1
进入iscsi目录,创建target:
/iscsi>create iqn.2015-02.com.sg:disk1
/iscsi> ls
o- iscsi..............................................................................................................[Targets: 1]
o- iqn.2015-02.com.sg:disk1............................................................................................[TPGs: 1]
3、在target上面创建一个lun;
进入/iscsi/iqn.2015-02.com.sg:disk1/tpg1目录:
/iscsi/iqn.20...sg:disk1/tpg1> ls
o- tpg1.....................................................................................................[no-gen-acls, no-auth]
o- acls................................................................................................................[ACLs: 0]
o- luns................................................................................................................[LUNs: 0]
o- portals..........................................................................................................[Portals: 0]
acls目录创建共享密码:
/iscsi/iqn.20...sg:disk1/tpg1> acls/ createiqn.2015-02.com.sg:diskpasswd
创建lun:
/iscsi/iqn.20...sg:disk1/tpg1> luns/ create /backstores/block/block1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2015-02.com.sg:diskpasswd
/iscsi/iqn.20...sg:disk1/tpg1> luns/ create /backstores/block/block2
Created LUN 1.
Created LUN 1->1 mapping in node ACL iqn.2015-02.com.sg:diskpasswd
o-luns..........................................................................................................[LUNs: 2]
| | o- lun0.......................................................................................[block/block1 (/dev/sdb7)]
| | o- lun1.......................................................................................[block/block2 (/dev/sdb8)]
portal创建共享端口和地址:
/iscsi/iqn.20...sg:disk1/tpg1> portals/ create 10.35.89.32
Using default IP port 3260
Created network portal 10.35.89.32:3260.
exit退出并保存:
Configurationsaved to /etc/target/saveconfig.json
配置文件保存在:/etc/target/saveconfig.json,可以直接修改配置文件
三、客户端配置iscsi连接
安装target包:
[root@client ~]# yum install target\* -y
查看fuw服务器端共享的内容:
[root@client ~]# iscsiadm -m discovery -t st -p 10.35.89.32
10.35.89.32:3260,1 iqn.2015-02.com.sg:disk1
编辑/etc/iscsi/initiatorname.iscsi文件,配置服务器端共享的名字和密码:
InitiatorName=iqn.2015-02.com.sg:diskpasswd
重启iscscid服务:
[root@client~]# systemctl restart iscsid.service
挂载服务器端共享的内容:
[root@client~]# iscsiadm -m node -T iqn.2015-02.com.sg:disk1 -p 10.35.89.32 -l
挂载成功后,使用fdisk命令即可查看到新增加的两块磁盘:
断开挂载的连接:
[root@client ~]# iscsiadm -m node -T iqn.2015-02.com.sg:disk1 -p 10.35.89.32 -u
使用fdisk命令划分共享的磁盘,格式化,并挂载文件夹,编辑fstab文件设置开机自动挂载:
[root@client ~]# fdisk /dev/sdb
DeviceBoot Start End Blocks Id System
/dev/sdb1 8192 114687 53248 83 Linux
[root@client~]# mkfs.xfs /dev/sdb1
[root@client/]# mount /dev/sdb1 /aa
编辑fstab文件时候,将default换成_netdev参数:
/dev/sdb1 /aa xfs _netdev 0 0
本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-04/116093.htm