rhel7 iscsi
服务器
[root@server0 /]# yum -y install target*
[root@server0 /]# fdisk /dev/vdb
[root@server0 /]# partprobe
[root@server0 /]# ll /dev/vd*
brw-rw----. 1 root disk 253, 0 Oct 14 12:52 /dev/vda
brw-rw----. 1 root disk 253, 1 Oct 14 2015 /dev/vda1
brw-rw----. 1 root disk 253, 16 Oct 14 12:52 /dev/vdb
brw-rw----. 1 root disk 253, 17 Oct 14 2015 /dev/vdb1
brw-rw----. 1 root disk 253, 18 Oct 14 12:52 /dev/vdb2
[root@server0 /]# targetcli
/> backstores/block create dev=/dev/vdb2 name=hrr
/> cd iscsi
/iscsi> create iqn.2015-10.com.example:server0
/iscsi> cd iqn.2015-10.com.example:server0/tpg1/
/iscsi/iqn.20...:server0/tpg1> acls/ create iqn.2015-10.com.example:desktop0
/iscsi/iqn.20...:server0/tpg1> luns/ create /backstores/block/hrr
/iscsi/iqn.20...:server0/tpg1> portals/ create 172.25.0.11
/iscsi/iqn.20...:server0/tpg1> exit
[root@server0 /]# systemctl start target
[root@server0 /]# systemctl enable target
[root@server0 /]# firewall-cmd --permanent --add-port=3260/tcp
success
[root@server0 /]# firewall-cmd --reload
success
客户机
[root@desktop0 /]# yum -y install iscsi-initiator-utils.i686
[root@desktop0 /]# mkdir /mnt/abc
[root@desktop0 /]# man iscsiadm |grep EXAMPLE -A10
EXAMPLES
Discover targets at a given IP address:
iscsiadm --mode discoverydb --type sendtargets --portal 192.168.1.10 --discover
Login, must use a node record id found by the discovery:
iscsiadm --mode node --targetname iqn.2001-05.com.doe:test --portal 192.168.1.1:3260 --login
Logout:
[root@desktop0 /]# systemctl restart iscsi iscsid
[root@desktop0 /]# systemctl enable iscsi iscsid
[root@desktop0 /]# iscsiadm --mode discoverydb --type sendtargets --portal 172.25.0.11 --discover
172.25.0.11:3260,1 iqn.2015-10.com.example:server0
[root@desktop0 /]# iscsiadm --mode node --targetname iqn.2015-10.com.example:desktop0 --portal 172.25.0.11:3260 --login
iscsiadm: No records found
[root@desktop0 /]# ls -L /dev/sd*
/dev/sda
[root@desktop0 /]# ls -l /dev/disk/by-path/ip-172.25.0.11\:3260-iscsi-iqn.2015-10.com.example\:server0-lun-0
lrwxrwxrwx. 1 root root 9 Oct 14 15:39 /dev/disk/by-path/ip-172.25.0.11:3260-iscsi-iqn.2015-10.com.example:server0-lun-0 -> ../../sda
[root@desktop0 /]# fdisk /dev/sda
[root@desktop0 /]# ll /dev/sd*
brw-rw----. 1 root disk 8, 0 Oct 14 15:40 /dev/sda
brw-rw----. 1 root disk 8, 1 Oct 14 15:40 /dev/sda1
[root@desktop0 /]# mkfs.xfs /dev/sda1
meta-data=/dev/sda1 isize=256 agcount=8, agsize=16000 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=128000, imaxpct=25
= sunit=0 s blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@desktop0 /]# mount /dev/sda1 /mnt/abc/
[root@desktop0 /]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 xfs 11G 3.4G 7.4G 32% /
devtmpfs devtmpfs 950M 0 950M 0% /dev
tmpfs tmpfs 966M 82k 966M 1% /dev/shm
tmpfs tmpfs 966M 18M 948M 2% /run
tmpfs tmpfs 966M 0 966M 0% /sys/fs/cgroup
//server0/hrr cifs 11G 3.3G 7.5G 31% /mnt/hrr
/dev/sda1 xfs 521M 27M 495M 6% /mnt/abc
[root@desktop0 /]# vim /etc/fstab
/dev/sda1/mnt/abc xfs defaults,_netdev 0 0
[root@desktop0 ~]# ll /dev/sd*
brw-rw----. 1 root disk 8, 0 Oct 14 16:44 /dev/sda
brw-rw----. 1 root disk 8, 1 Oct 14 15:43 /dev/sda1
brw-rw----. 1 root disk 8, 2 Oct 14 16:44 /dev/sda2
[root@desktop0 ~]# mkfs.xfs /dev/sda2
[root@desktop0 ~]# blkid /dev/sda2
/dev/sda2: UUID="d8b12595-9d5d-4988-a4fa-387774242ca8" TYPE="xfs"
[root@desktop0 ~]# vim /etc/fstab
UUID=d8b12595-9d5d-4988-a4fa-387774242ca8 /mnt/uuid xfs defaults,_netdev 0 0
[root@desktop0 ~]# mkdir /mnt/uuid
[root@desktop0 ~]# mount -a
[root@desktop0 ~]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 xfs 11G 3.4G 7.4G 32% /
devtmpfs devtmpfs 950M 0 950M 0% /dev
tmpfs tmpfs 966M 82k 966M 1% /dev/shm
tmpfs tmpfs 966M 18M 948M 2% /run
tmpfs tmpfs 966M 0 966M 0% /sys/fs/cgroup
//server0/hrr