一、服务器用Linux,客户端用Windows访问
1、准备一个分区
[root@localhost ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3):
First sector (50759680-83886079, default 50759680): +10G
Value out of range.
First sector (50759680-83886079, default 50759680):
Using default value 50759680
Last sector, +sectors or +size{K,M,G} (50759680-83886079, default 83886079):
Using default value 83886079
Partition 3 of type Linux and of size 15.8 GiB is set
Command (m for help): p
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b0f8f
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 50759679 25174016 8e Linux LVM
/dev/sda3 50759680 83886079 16563200 83 Linux
Command (m for help): w
The partition table has been altered!
[root@localhost ~]# partprobe
2、装包,关闭防火墙和selinux
[root@localhost ~]# yum install targetcli
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
3、启动服务
[root@localhost ~]# systemctl start target
4、创建
[root@localhost ~]# targetcli
targetcli shell version 2.1.fb41
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
4.1、查看菜单结构
4.4、添加targe
4.8、重启服务
[root@localhost ~]# systemctl restart target
二、服务器用Linux,客户端用Linux访问
服务器的配置如上述,现在我们来看一下用Linux做客户端该怎么配置。
1、装包
[root@localhost ~]# mount /dev/sr0 /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# yum install iscsi-initiator-utils.i686 -y
2、发现目标
[root@localhost ~]# iscsiadm -mode node -T iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.1901fd98d2f4 -p 192.168.100.160:3260 -l
Logging in to [iface: default, target: iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.1901fd98d2f4, portal: 192.168.100.160,3260] (multiple)
Login to [iface: default, target: iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.1901fd98d2f4, portal: 192.168.100.160,3260] successful.
3、挂载磁盘
[root@localhost ~]# iscsiadm -mode node -T iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.1901fd98d2f4 -p 192.168.100.160:3260 -l
Logging in to [iface: default, target: iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.1901fd98d2f4, portal: 192.168.100.160,3260] (multiple)
Login to [iface: default, target: iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.1901fd98d2f4, portal: 192.168.100.160,3260] successful.
4、查看挂载情况
5、查看分区
[root@localhost ~]# ll /dev/disk/by-path/
total 0
lrwxrwxrwx. 1 root root 9 Apr 16 11:29 ip-192.168.100.160:3260-iscsi-iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.1901fd98d2f4-lun-0 -> ../../sdb
lrwxrwxrwx. 1 root root 10 Apr 16 11:29 ip-192.168.100.160:3260-iscsi-iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.1901fd98d2f4-lun-0-part1 -> ../../sdb1
lrwxrwxrwx. 1 root root 10 Apr 16 11:29 ip-192.168.100.160:3260-iscsi-iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.1901fd98d2f4-lun-0-part2 -> ../../sdb2
lrwxrwxrwx. 1 root root 9 Apr 16 2019 pci-0000:00:10.0-scsi-0:0:0:0 -> ../../sda
lrwxrwxrwx. 1 root root 10 Apr 16 2019 pci-0000:00:10.0-scsi-0:0:0:0-part1 -> ../../sda1
lrwxrwxrwx. 1 root root 10 Apr 16 2019 pci-0000:00:10.0-scsi-0:0:0:0-part2 -> ../../sda2
lrwxrwxrwx. 1 root root 9 Apr 16 2019 pci-0000:02:04.0-ata-2.0 -> ../../sr0
6、查看日志
[root@localhost ~]# grep sdb /var/log/messages
Apr 16 11:29:02 localhost kernel: sd 33:0:0:0: [sdb] 33126400 512-byte logical blocks: (16.9 GB/15.7 GiB)
Apr 16 11:29:02 localhost kernel: sd 33:0:0:0: [sdb] Write Protect is off
Apr 16 11:29:02 localhost kernel: sd 33:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
Apr 16 11:29:02 localhost kernel: sdb: sdb1 sdb2
Apr 16 11:29:02 localhost kernel: sd 33:0:0:0: [sdb] Attached SCSI disk
7、自动挂载
编辑文件,添加
[root@localhost ~]# vim /etc/fstab
UUID=2bcbfdef-f655-4b96-90cd-9b5661995de6 /test xfs defaults,_netdev 0 0
添加磁盘的UUID,通过blkid查看