通过局域网在客户端访问使用服务端的磁盘需要借助到SAN
客户端
首先服务端需要先安装 targetd 和 targetcli
[root@localhost ~]# yum -y install targetd targetcli
在服务端准备好要共享的磁盘
开始,重启,和查看服务是否开始
[root@localhost ~]# systemctl start target
[root@localhost ~]# systemctl enable target
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service
to /usr/lib/systemd/system/target.service.
[root@server ~]# systemctl status target
● target.service - Restore LIO kernel target configuration
Loaded: loaded (/usr/lib/systemd/system/target.service; enabled; vendor
preset: disabled)
Active: active (exited) since Sat 2020-05-09 18:12:28 CST; 9s ago
Main PID: 17317 (code=exited, status=0/SUCCESS)
...
设置防火墙规则,开放3260端口,使用 tcp 传输协议,让服务可以生效
[root@localhost ~]# firewall-cmd --add-port=3260/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-ports
3260/tcp
进入 targetcli 服务进行配置
对于要共享的磁盘进行命名
/> /backstores/block create server0.disk1 /dev/sdc
Created block storage object server0.disk1 using /dev/sdc.
创建用户(为了让客户端访问到时可以进行登录)
/> /iscsi create iqn.2022-04.com.bdqn:disk1
Created target iqn.2022-04.com.bdqn:disk1.
Created TPG 1.
Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260.
创建白名单
/> /iscsi/iqn.2022-04.com.bdqn:disk1/tpg1/acls create iqn.202005.com.bdqn:client1
Created Node ACL for iqn.2022-04.com.bdqn:client1
将用户与刚刚命名的磁盘进行绑定
/> /iscsi/iqn.2022-04.com.bdqn:disk1/tpg1/luns create /backstores/block/server0.disk1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2022-05.com.bdqn:client1
到这里服务端就配置完成了,现在需要配置客户端
服务端
先安装 iscsi-initiator-utils 服务
[root@localhost ~]# yum -y install iscsi-initiator-utils
使用 vi 给 initiator 命名 ps:这个名字,时刚刚服务端里我们设置的名字,里面会有数据需要修改一下
InitiatorName=iqn.2022-04.com.bdqn:disk1/tpg1/acls
启动服务
[root@localhost ~]# systemctl start iscsi
[root@localhost ~]# systemctl enable iscsi
Created symlink from /etc/systemd/system/remote-fs.target.wants/iscsi.service to /usr/lib/systemd/system/iscsi.service.
发现存储 IP是刚刚服务端的IP
[root@localhost ~]# iscsiadm -m discovery -t st -p 192.168.190.130
192.168.190.130:3260,1 iqn.2022-04.com.bdqn:disk1
登录存储/连接target
[root@localhost ~]# iscsiadm -m discovery -t st -p 192.168.190.130 -l
192.168.190.130:3260,1 iqn.2022-04.com.bdqn:disk1
Logging in to [iface: default, target: iqn.2022-04.com.bdqn:disk1, portal: 192.168.190.130,3260] (multiple)
iscsiadm: Could not login to [iface: default, target: iqn.2022-04.com.bdqn:disk1, portal: 192.168.190.130,3260].
iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)
验证 iscsi 连接,查看是否得到外界磁盘
[root@localhost ~]# lsscsi
[1:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0
[2:0:0:0] disk VMware, VMware Virtual S 1.0 /dev/sda
这时就可以操作本地磁盘一样来操作 iscsi 磁盘了