[Linux服务器] Linux 磁盘共享存储

1543 0
Honkers 2025-3-18 10:25:41 | 显示全部楼层 |阅读模式

1.安装服务

  1. [root@server ~]# yum -y install targetd targetcli #安装服务
复制代码

2.启动服务

  1. [root@localhost qtx]# systemctl start target
  2. [root@localhost qtx]# systemctl enable target
  3. [root@localhost qtx]# systemctl status target
复制代码

3.设置防火墙

  1. [root@localhost qtx]# firewall-cmd --add-port=3260/tcp --permanent
  2. success
  3. [root@localhost qtx]# firewall-cmd --reload
  4. success
  5. [root@localhost qtx]# firewall-cmd --list-ports
  6. 3260/tcp
复制代码

一、客户端

1.指定磁盘

  1. [root@localhost qtx]# targetcli
  2. targetcli shell version 2.1.53
  3. Copyright 2011-2013 by Datera, Inc and others.
  4. For help on commands, type 'help'.
  5. /> /backstores/block create fwq0.disk1 /dev/sdb
  6. Created block storage object fwq0.disk1 using /dev/sdb.
  7. /> exit
  8. Global pref auto_save_on_exit=true
  9. Configuration saved to /etc/target/saveconfig.json
复制代码

2.创建iqn名字和iscsi对象

  1. [root@localhost qtx]# targetcli
  2. targetcli shell version 2.1.53
  3. Copyright 2011-2013 by Datera, Inc and others.
  4. For help on commands, type 'help'.
  5. /> /iscsi create iqn.2022-04.com.qtx:sdb1
  6. Created target iqn.2022-04.com.qtx:sdb1.
  7. Created TPG 1.
  8. Global pref auto_add_default_portal=true
  9. Created default portal listening on all IPs (0.0.0.0), port 3260.
  10. /> exit
  11. Global pref auto_save_on_exit=true
  12. Last 10 configs saved in /etc/target/backup/.
  13. Configuration saved to /etc/target/saveconfig.json
复制代码

3.设置iscsi对象和客户端ip

  1. [root@localhost qtx]# targetcli
  2. targetcli shell version 2.1.53
  3. Copyright 2011-2013 by Datera, Inc and others.
  4. For help on commands, type 'help'.
  5. /> /iscsi/iqn.2022-04.com.qtx:sdb1/tpg1/acls create iqn.2022-04.com.qtx:user1
  6. Created Node ACL for iqn.2022-04.com.qtx:user1
  7. /> exit
  8. Global pref auto_save_on_exit=true
  9. Last 10 configs saved in /etc/target/backup/.
  10. Configuration saved to /etc/target/saveconfig.json
复制代码

4.创建lun    绑定块

  1. [root@localhost qtx]# targetcli
  2. targetcli shell version 2.1.53
  3. Copyright 2011-2013 by Datera, Inc and others.
  4. For help on commands, type 'help'.
  5. /> /iscsi/iqn.2022-04.com.qtx:sdb1/tpg1/luns create
复制代码

二、客户端

1.安装工具

  1. [root@localhost qtx]# yum -y install targetd targetcli
复制代码

2.initiator命名

  1. [root@client ~]# vim /etc/iscsi/initiatorname.iscsi
  2. InitiatorName=iqn.2022-04.com.qts:sdb1
复制代码

 3.启动服务

  1. [root@localhost qtx]# systemctl start iscsi
  2. [root@localhost qtx]# systemctl enable iscsi
  3. [root@localhost qtx]# systemctl status iscsi
复制代码

4.发现存储

  1. [root@localhost qtx]# iscsiadm -m discovery -t st -p 192.168.190.129
  2. 192.168.190.129:3260,1 iqn.2022-04.com.qtx:sdb1
复制代码

5.登陆存储     连接

  1. [root@localhost qtx]# iscsiadm -m discovery -t st -p 192.168.190.129 -l
复制代码

6.验证

  1. [root@localhost qtx]# lsscsi
复制代码
  1. [root@localhost qtx]# gdisk /dev/sdb
  2. Number Start (sector) End (sector) Size Code Name
  3. 1 2048 10487807 5.0 GiB 8300 Linux filesystem
  4. 2 10487808 20971486 5.0 GiB 8300 Linux filesystem
  5. [root@localhost qtx]# partprobe /dev/sdb
  6. [root@localhost qtx]# partprobe /dev/sdb
  7. [root@localhost qtx]# partprobe /dev/sdb
  8. [root@localhost qtx]# cat /proc/partitions
  9. major minor #blocks name
  10. 8 16 10485760 sdb
  11. 8 17 5242880 sdb1
  12. 8 18 5241839 sdb2
复制代码
  1. [root@localhost qtx]# mkdir /mnt/iscsi
  2. [root@localhost qtx]# mkfs.xfs /dev/sdb1
  3. [root@localhost qtx]# mount /dev/sdb1 /mnt/iscsi/
  4. [root@localhost qtx]# mount | tail -1
  5. [root@localhost qtx]# df -hT /mnt/iscsi/
复制代码

  1. [root@localhost qtx]# targetcli
  2. /> cd /iscsi/iqn.2022-04.com.qtx:disk1/tpg1/portals/
  3. /iscsi/iqn.20.../tpg1/portals> delete 0.0.0.0 3260
  4. Deleted network portal 0.0.0.0:3260
  5. /iscsi/iqn.20.../tpg1/portals> create 192.168.192.129 3260
  6. Using default IP port 3260
  7. Created network portal 192.168.190.:3260.
  8. /iscsi/iqn.20.../tpg1/portals> exit
  9. Global pref auto_save_on_exit=true
  10. Last 10 configs saved in /etc/target/backup/.
  11. Configuration saved to /etc/target/saveconfig.json
  12. [root@localhost qtx]# systemctl restart target.service
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2026 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行