server:

[server]# yum –y install targetcli
[server]# systemctl enable target
[server]# systemctl start target

先分一个2G的空间出来,此处省略了。

[server]# targetcli
[server]# /backstores/block create iscsi-store /dev/vda7 //vda7是我在上面分出来的,实际上根据自己分的盘来设置
[server]# /iscsi create iqn.2015-02.com.example:system1
[server]# /iscsi/iqn.2015-02.com.example:system1/tpg1/acls/ create iqn.2015-02.com.example:system2 //客户端挂载使用此共享的凭据
[server]# /iscsi/iqn.2015-02.com.example:system1/tpg1/luns create /backstores/block/iscsi-store
[server]# /iscsi/iqn.2015-02.com.example:system1/tpg1/portals/ create 192.168.0.150+X
[server]# exit
[server]# systemctl restart target
[server]# firewall-cmd --permanent --add-port=3260/tcp
[server]# firewall-cmd --reload

client:

[client]# yum –y install iscsi-
[client]# vim /etc/iscsi/initiatorname.iscsi

InitiatorName=iqn.2015-02.com.example:system2

[client]# systemctl restart iscsi
[client]# systemctl enable iscsi
[client]# iscsiadm –m discovery –t st –p system1的IP //man iscsiadm 可查到此条命令
[client]# iscsiadm -m node –T iqn.2015-02.com.example:system1 –l //man iscsiadm 可查到此条命令
[client]# fdisk /dev/sda

然后分配一个1G的分区,此处我省略了。

[client]# mkfs.ext4 /dev/sda1
[client]# mkdir /mnt/data
[client]# vim /etc/fstab

/dev/sda1        /mnt/data       ext4   defaults,netdev    0    0

[client]# mount -a*