Linux总结笔记11-搭建ISCSI网络存储

一.配置ISCSI服务端(target)

1.在iscsi服务端添加硬盘,然后配置成RAID

注:也可以直接硬盘共享,不用做成RAID

[root@linux1 ~]# mdadm -Cv /dev/md0 -n 3 -l 5 -x 1 /dev/sdb /dev/sdc /dev/sdd /dev/sde
//创建RAID5卷,一块硬盘用做备份盘
[root@linux1 ~]# mdadm -D /dev/md0
UUID : b70b4f22:c56bc570:823cea63:7aa252bf
//查看所创建的RAID5卷的UUID值

2.创建RAID阵列配置文件

[root@linux1 ~]# cat /etc/mdadm.conf
DEVICE /dev/sdb /dev/sdc /dev/sdd /dev/sde
ARRAY /dev/md0 UUID=b70b4f22:c56bc570:823cea63:7aa252bf

3.安装ISCSI target服务程序,并启动

[root@linux1 ~]# yum -y install targetd targetcli
targetd为服务程序,targetcli为管理工具
[root@linux1 ~]# systemctl restart targetd
[root@linux1 ~]# systemctl enable target

4.使用targetcli工具创建存储对象

[root@linux1 ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb41
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         //进入block目录
/backstores/block> create disk0 /dev/md0        //使用/dev/md0创建设备disk0
Created block storage object disk0 using /dev/md0.
/backstores/block> cd ../..
/> ls
o- / ................................................................ [...]
  o- backstores ..................................................... [...]
  | o- block ......................................... [Storage Objects: 1]
  | | o- disk0 ................ [/dev/md0 (40.0GiB) write-thru deactivated]
  | o- fileio ........................................ [Storage Objects: 0]
  | o- pscsi ......................................... [Storage Objects: 0]
  | o- ramdisk ....................................... [Storage Objects: 0]
  o- iscsi ................................................... [Targets: 0]
  o- loopback ................................................ [Targets: 0]
/> cd iscsi         //进入iscsi目录
/iscsi> create      //创建iSCSI target目标
Created target iqn.2003-01.org.linux-iscsi.linux1.x8664:sn.15ca3842559f.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> cd iqn.2003-01.org.linux-iscsi.linux1.x8664:sn.15ca3842559f/
/iscsi/iqn.20....15ca3842559f> cd tpg1/
/iscsi/iqn.20...3842559f/tpg1> cd luns 
/iscsi/iqn.20...59f/tpg1/luns> create /backstores/block/disk0       //创建LUN设备 
Created LUN 0.
/iscsi/iqn.20...59f/tpg1/luns> cd ..
/iscsi/iqn.20...3842559f/tpg1> cd acls 
/iscsi/iqn.20...59f/tpg1/acls> create iqn.2003-01.org.linux-iscsi.linux1.x8664:sn.15ca3842559f:client   //创建访问控制列表
Created Node ACL for iqn.2003-01.org.linux-iscsi.linux1.x8664:sn.15ca3842559f:client
Created mapped LUN 0.
/iscsi/iqn.20...59f/tpg1/acls> cd ..
/iscsi/iqn.20...3842559f/tpg1> cd portals
/iscsi/iqn.20.../tpg1/portals> create 192.168.100.10        //添加允许监听的IP地址
Using default IP port 3260
Created network portal 192.168.100.10:3260.
/iscsi/iqn.20.../tpg1/portals> ls /
o- / ................................................................ [...]
  o- backstores ..................................................... [...]
  | o- block ......................................... [Storage Objects: 1]
  | | o- disk0 .................. [/dev/md0 (40.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.2003-01.org.linux-iscsi.linux1.x8664:sn.15ca3842559f . [TPGs: 1]
  |   o- tpg1 ...................................... [no-gen-acls, no-auth]
  |     o- acls ................................................. [ACLs: 1]
  |     | o- iqn.2003-01.org.linux-iscsi.linux1.x8664:sn.15ca3842559f:client  [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ........................ [lun0 block/disk0 (rw)]
  |     o- luns ................................................. [LUNs: 1]
  |     | o- lun0 ................................ [block/disk0 (/dev/md0)]
  |     o- portals ........................................... [Portals: 1]
  |       o- 192.168.100.10:3260 ..................................... [OK]
  o- loopback ................................................ [Targets: 0]
/iscsi/iqn.20.../tpg1/portals> exit     //保存退出
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

5.创建防火墙允许规则

[root@linux1 ~]# firewall-cmd --permanent --add-port=3260/tcp
[root@linux1 ~]# firewall-cmd --reload

二.配置ISCSI客户端(initiator)

1.安装iscsi 客户端服务程序

[root@linux2 ~]# yum -y install iscsi-initiator-utils

2.编辑的iscsi客户端名称文件

[root@linux2 ~]# vim /etc/iscsi/initiatorname.iscsi    
InitiatorName=iqn.2003-01.org.linux-iscsi.linux1.x8664:sn.15ca3842559f:client

3.重启iscsi客户端服务程序

[root@linux2 ~]# systemctl restart iscsid
[root@linux2 ~]# systemctl enable iscsid

4.发现iscsi服务端的可用存储设备

[root@linux2 ~]# iscsiadm -m discovery -t st -p 192.168.100.10
192.168.100.10:3260,1 iqn.2003-01.org.linux-iscsi.linux1.x8664:sn.15ca3842559f

5.连接iscsi服务端的可用存储设备

[root@linux2 ~]# iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.linux1.x8664:sn.15ca3842559f -p 192.168.100.10 --login
Logging in to [iface: default, target: iqn.2003-01.org.linux-iscsi.linux1.x8664:sn.15ca3842559f, portal: 192.168.100.10,3260] (multiple)
Login to [iface: default, target: iqn.2003-01.org.linux-iscsi.linux1.x8664:sn.15ca3842559f, portal: 192.168.100.10,3260] successful.

6.格式化,挂载使用

连接iscsi服务端存储设备后使用fdisk -l可查看到多了已快磁盘,然后格式化,挂载使用即可 
[root@linux2 ~]# mkfs.xfs /dev/sdb      //格式化
[root@linux2 ~]# mkdir /iscsi           //创建挂载点
[root@linux2 ~]# mount /dev/sdb /iscsi  //挂载
[root@linux2 ~]# df -h                  //查看挂载情况

[root@linux2 ~]# blkid                  //查看设备的UUID
/dev/sdb: UUID="2ed7d75c-bf4c-4ab1-8ca7-79f854564943" TYPE="xfs" 

[root@linux2 ~]# cat /etc/fstab         //写入fstab
UUID="2ed7d75c-bf4c-4ab1-8ca7-79f854564943"     /iscsi  xfs     defaults,_netdev   00
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值