天道神诀--IPSAN(iscsi配置)(linux7)

2021/11/6 7:13:55

本文主要是介绍天道神诀--IPSAN(iscsi配置)(linux7),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1. 查看当前磁盘信息

[root@linux ~]# lsblk

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sdb      8:16   0   10G  0 disk

sr0     11:0    1  4.3G  0 rom  

sda      8:0    0   30G  0 disk

├─sda2   8:2    0   26G  0 part /

└─sda1   8:1    0    4G  0 part [SWAP]


2. 将sdb磁盘进行分区

[root@linux ~]# lsblk

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sdb      8:16   0   10G  0 disk

├─sdb2   8:18   0    5G  0 part

└─sdb1   8:17   0    5G  0 part

sr0     11:0    1  4.3G  0 rom  

sda      8:0    0   30G  0 disk

├─sda2   8:2    0   26G  0 part /

└─sda1   8:1    0    4G  0 part [SWAP]


3. 安装targetcli软件包
[root@linux ~]# yum -y install targetcli

4. 启动target服务

[root@linux ~]# systemctl enable target.service

[root@linux ~]# systemctl start target.service


5. 配置防火墙策略

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

[root@linux ~]# firewall-cmd --reload


6. 登陆targetcli配置管理界面

[root@linux ~]# targetcli

Warning: Could not load preferences file /root/.targetcli/prefs.bin.

targetcli shell version 2.1.fb46

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]

 o- vhost ............................................................................................................ [Targets: 0]

/> 


7.配置ISCSI服务端

/> /backstores/block create san1 /dev/sdb1                                                    【将sdb1分区创建为名为san1的块设备】

Created block storage object san1 using /dev/sdb1.

/> /backstores/block create san2 /dev/sdb2                                                    【将sdb2分区创建为名为san2的块设备】

Created block storage object san2 using /dev/sdb2.

/> /iscsi create iqn.2019-11.com.db:server                                                    【创建iscsi服务标识】

Created target iqn.2019-11.com.db:server.

Created TPG 1.

Global pref auto_add_default_portal=true

Created default portal listening on all IPs (0.0.0.0), port 3260.

/> cd iscsi/iqn.2019-11.com.db:server/tpg1/

/iscsi/iqn.20...b:server/tpg1> acls/ create iqn.2019-11.com.db:client1                        【创建客户端1访问的iqn标识】

Created Node ACL for iqn.2019-11.com.db:client1

/iscsi/iqn.20...b:server/tpg1> acls/ create iqn.2019-11.com.db:client2                        【创建客户端2访问的iqn标识】

Created Node ACL for iqn.2019-11.com.db:client2

/iscsi/iqn.20...b:server/tpg1> luns/ create /backstores/block/san1                            【将san1块设备创建lun映射】

Created LUN 0.

Created LUN 0->0 mapping in node ACL iqn.2019-11.com.db:client2

Created LUN 0->0 mapping in node ACL iqn.2019-11.com.db:client1

/iscsi/iqn.20...b:server/tpg1> luns/ create /backstores/block/san2                            【将san2块设备创建lun映射】

Created LUN 1.

Created LUN 1->1 mapping in node ACL iqn.2019-11.com.db:client2

Created LUN 1->1 mapping in node ACL iqn.2019-11.com.db:client1

注意:acls创建的数量和需要连接的客户端数据量一致,luns创建的数量和之前创建的块设备数量一致。
如需指定ip地址:

/iscsi/iqn.20...b:server/tpg1> portals/ delete 0.0.0.0 3260

Deleted network portal 0.0.0.0:3260

/iscsi/iqn.20...b:server/tpg1> portals/ create 192.168.22.131 3260

Using default IP port 3260

Created network portal 192.168.22.131:3260.


8. 查看配置信息并保存退出

/> ls

o- / ........................................................................................................................ [...]

 o- backstores .............................................................................................................. [...]

 | o- block .................................................................................................. [Storage Objects: 2]

 | | o- san1 ........................................................................... [/dev/sdb1 (0 bytes) write-thru activated]

 | | | o- alua ................................................................................................... [ALUA Groups: 1]

 | | |   o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]

 | | o- san2 ........................................................................... [/dev/sdb2 (0 bytes) write-thru activated]

 | |   o- alua ................................................................................................... [ALUA Groups: 1]

 | |     o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]

 | o- fileio ................................................................................................. [Storage Objects: 0]

 | o- pscsi .................................................................................................. [Storage Objects: 0]

 | o- ramdisk ................................................................................................ [Storage Objects: 0]

 o- iscsi ............................................................................................................ [Targets: 1]

 | o- iqn.2019-11.com.db:server ......................................................................................... [TPGs: 1]

 |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]

 |     o- acls .......................................................................................................... [ACLs: 2]

 |     | o- iqn.2019-11.com.db:client1 ........................................................................... [Mapped LUNs: 2]

 |     | | o- mapped_lun0 .................................................................................. [lun0 block/san1 (rw)]

 |     | | o- mapped_lun1 .................................................................................. [lun1 block/san2 (rw)]

 |     | o- iqn.2019-11.com.db:client2 ........................................................................... [Mapped LUNs: 2]

 |     |   o- mapped_lun0 .................................................................................. [lun0 block/san1 (rw)]

 |     |   o- mapped_lun1 .................................................................................. [lun1 block/san2 (rw)]

 |     o- luns .......................................................................................................... [LUNs: 2]

 |     | o- lun0 ...................................................................... [block/san1 (/dev/sdb1) (default_tg_pt_gp)]

 |     | o- lun1 ...................................................................... [block/san2 (/dev/sdb2) (default_tg_pt_gp)]

 |     o- portals .................................................................................................... [Portals: 1]

 |       o- 192.168.22.131:3260 .............................................................................................. [OK]

 o- loopback ......................................................................................................... [Targets: 0]

 o- vhost ............................................................................................................ [Targets: 0]

/> saveconfig                                                                                     【保存】

Configuration saved to /etc/target/saveconfig.json

/> exit                                                                                           【退出】 

Global pref auto_save_on_exit=true

Last 10 configs saved in /etc/target/backup/.

Configuration saved to /etc/target/saveconfig.json


至此ISCSI服务端配置完毕,客户端根据acls创建的iqn标识进行访问连接共享存储。

1. 安装软件包
[root@localhost ~]# yum install iscsi-initiator-utils -y

2. 发现共享出来的iSCSI的服务
[root@localhost ~]# iscsiadm -m discovery -t st -p 192.168.1.100
注释:-m:指什么动作      discovery:发现      -t:类型            st:发送终端类型(sendtargets)      -p:指定服务端地址
3. 配置initiator文件
[root@localhost ~]# echo "InitiatorName=iqn.2019-11.com.db:client1" > /etc/iscsi/initiatorname.iscsi
将服务端设置的acl名称写入到initiator文件,iSCSI协议会通过此文件内容进行验证
4. 重启iscsi的服务以及开机自启动
[root@localhost ~]# systemctl restart iscsid & systemctl enable iscsid

5. 登录iscsi服务端
[root@localhost ~]# iscsiadm -m node -T iqn.2019-11.com.db:server -p 192.168.1.100:3260 -l
注释:-m node:参数为将客户端所在主机作为一台节点服务器      -T:服务端配置iscsi服务的iqn      -p:服务端配置的portal地址信息      -l:登录
6. 查看共享磁盘信息

[root@localhost ~]# lsblk

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda      8:0    0   50G  0 disk

├─sda1   8:1    0  300M  0 part /boot

├─sda2   8:2    0  3.9G  0 part [SWAP]

└─sda3   8:3    0 45.9G  0 part /

sdb      8:16   0    5G  0 disk

sdc      8:32   0   25G  0 disk


7. 取消iscsi登陆

[root@localhost ~]# umount /dev/sdb /mnt/data               -----如果磁盘正在挂载使用,建议先卸载

[root@localhost ~]# iscsiadm -m node -T iqn.2019-11.com.db:server -u




这篇关于天道神诀--IPSAN(iscsi配置)(linux7)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程