環境:Centos6.8 64位系統
服務端: 10.2.11.220/24
客戶端: 10.2.11.233/24
一)配置服務端
[root@scsi ~]# yum -y install scsi-target-utils
查看:
[root@scsi ~]# rpm -ql scsi-target-utils
/etc/rc.d/init.d/tgtd
/etc/sysconfig/tgtd
/etc/tgt/targets.conf-----配置文件
/usr/sbin/tgt-admin
/usr/sbin/tgt-setup-lun
/usr/sbin/tgtadm
/usr/sbin/tgtd----啟動文件
/usr/sbin/tgtimg
/usr/share/doc/scsi-target-utils-1.0.24
/usr/share/doc/scsi-target-utils-1.0.24/README
/usr/share/doc/scsi-target-utils-1.0.24/README.iscsi
/usr/share/doc/scsi-target-utils-1.0.24/README.iser
/usr/share/doc/scsi-target-utils-1.0.24/README.lu_configuration
/usr/share/doc/scsi-target-utils-1.0.24/README.mmc
/usr/share/man/man5/targets.conf.5.gz
/usr/share/man/man8/tgt-admin.8.gz
/usr/share/man/man8/tgt-setup-lun.8.gz
/usr/share/man/man8/tgtadm.8.gz
[root@scsi ~]# lsmod | grep scsi
mptscsih 36638 1 mptspi
mptbase 93615 2 mptspi,mptscsih
scsi_transport_spi 25447 1 mptspi
啟動服務
[root@scsi ~]# service tgtd start
Starting SCSI target daemon: [ OK ]
[root@scsi ~]# ss -tunlp|grep 3260
tcp LISTEN 0 128 :::3260 :::* users:(("tgtd",1668,5),("tgtd",1671,5))
tcp LISTEN 0 128 *:3260 *:* users:(("tgtd",1668,4),("tgtd",1671,4))
2)
在服務器上創建一個分區/dev/sdb1,/dev/sdb2然后共享出去
創建一個target
[root@scsi ~]# tgtadm -L iscsi -m target -o new -t 1 -T iqn-2018-01-17.yuki.rhce:disk
[root@scsi ~]# tgt-admin --show
Target 1: iqn-2018-01-17.yuki.rhce:disk
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: null
Backing store path: None
Backing store flags:
Account information:
ACL information:
(如果要刪除這個target,就執行 tgtadm -L iscsi -m target -o delete -t 1 )
創建lun
[root@scsi ~]# tgtadm -L iscsi -m logicalunit -o new -t 1 --lun 1 -b /dev/sdb1
[root@scsi ~]# tgtadm -L iscsi -m logicalunit -o new -t 1 --lun 2 -b /dev/sdb2
(如果上面報tgtadm: invalid request,就執行以下partx -a /dev/sdb
[root@scsi ~]# partx -a /dev/sdb
)
查看
[root@scsi ~]# tgt-admin --show
Target 1: iqn-2018-01-17.yuki.rhce:disk
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 21484 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/sdb1
Backing store flags:
LUN: 2
Type: disk
SCSI ID: IET 00010002
SCSI SN: beaf12
Size: 5379 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/sdb2
Backing store flags:
Account information:
ACL information:
3)創建ACL,誰可以訪問這個lun
[root@scsi ~]# tgtadm -L iscsi -m target --op bind -t 1 -I 10.2.11.0/24
解綁:
[root@scsi ~]# tgtadm -L iscsi -m target --op unbind -t 1 -I 10.2.11.0/24
注意:
以上配置,電腦重啟后就會失效,如果想永久保存,有2中解決辦法
1)把以上命令寫到/etc/rc.local,讓電腦開機自動執行
2)把以上命令導入到配置文件/etc/tgt/targets.conf
[root@scsi ~]# cp /etc/tgt/targets.conf{,.ori}
[root@scsi ~]# tgt-admin --dump > /etc/tgt/targets.conf
[root@scsi ~]# cat /etc/tgt/targets.conf
default-driver iscsi
<target iqn.2018-01.cc.rhce:disk>
backing-store /dev/sdb3
incominguser tom01 PLEASE_CORRECT_THE_PASSWORD
initiator-address 10.2.11.0/24
</target>
<target iqn-2018-01-17.yuki.rhce:disk>
backing-store /dev/sdb1
backing-store /dev/sdb2
incominguser tom PLEASE_CORRECT_THE_PASSWORD
initiator-address 10.2.11.0/24
</target>
二)配置客戶端
1)安裝軟件
[root@node2 ~]# yum -y install iscsi-initiator-utils
[root@node2 ~]# echo "InitiatorName=`iscsi-iname -p iqn-2018-01-17.yuki.rhce:disk`">/etc/iscsi/initiatorname.iscsi
[root@node2 ~]# echo "InitiatorAlias=initiator1" >> /etc/iscsi/initiatorname.iscsi
[root@node2 ~]# service iscsi start #啟動服務,需要啟動兩個服務
[root@node2 ~]# service iscsid start
[root@node2 ~]# chkconfig iscsi on
[root@node2 ~]# chkconfig iscsid on
2)發現操作
[root@node2 ~]# iscsiadm -m discovery -t st -p 10.2.11.220
10.2.11.220:3260,1 iqn-2018-01-17.yuki.rhce:disk
連接:
[root@node2 ~]# iscsiadm -m node -T iqn-2018-01-17.yuki.rhce:disk -p 10.2.11.220 -l
Logging in to [iface: default, target: iqn-2018-01-17.yuki.rhce:disk, portal: 10.2.11.220,3260] (multiple)
Login to [iface: default, target: iqn-2018-01-17.yuki.rhce:disk, portal: 10.2.11.220,3260] successful.
如果要退出的話,執行
[root@node2 ~]# iscsiadm -m node -T iqn-2018-01-17.yuki.rhce:disk -p 10.2.11.220 -u
3)查看
[root@node2 ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21484399104 bytes
64 heads, 32 sectors/track, 20489 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdb: 5379 MB, 5379333120 bytes
166 heads, 62 sectors/track, 1020 cylinders
Units = cylinders of 10292 * 512 = 5269504 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
特點:
1)開機自動連接
/etc/iscsi/iscsi.conf
node.startup = automatic
2) 客戶端怎么找到服務器
[root@node2 ~]# cd /var/lib/iscsi/
[root@node2 iscsi]# ll
total 24
drwxr-xr-x. 2 root root 4096 Jul 12 2017 ifaces
drwxr-xr-x. 2 root root 4096 Jul 12 2017 isns
drwxr-xr-x. 3 root root 4096 Jan 18 20:07 nodes
drwxr-xr-x. 3 root root 4096 Jan 17 23:11 send_targets
drwxr-xr-x. 2 root root 4096 Jul 12 2017 slp
drwxr-xr-x. 2 root root 4096 Jul 12 2017 static
[root@node2 iscsi]# cd nodes/
[root@node2 nodes]# ll
total 4
drw-------. 3 root root 4096 Jan 18 20:07 iqn-2018-01-17.yuki.rhce:disk
[root@node2 nodes]# cd ..
[root@node2 iscsi]# cd nodes/
[root@node2 nodes]# ll
total 4
drw-------. 3 root root 4096 Jan 18 20:07 iqn-2018-01-17.yuki.rhce:disk
[root@node2 nodes]# cd ..
[root@node2 iscsi]# cd send_targets/
[root@node2 send_targets]# ll
total 4
drw-------. 2 root root 4096 Jan 18 20:07 10.2.11.220,3260
三)創建基于用戶的認證
[root@scsi ~]# tgtadm -L iscsi -m account -o new -u tom -p redhat(創建用戶名tom,密碼:redhat)
[root@scsi ~]# tgtadm -L iscsi -m account -o bind -t 1 -u tom (把用戶關聯到target)
客戶端連接
[root@node2 ~]# iscsiadm -m node -T iqn-2018-01-17.yuki.rhce:disk -p 10.2.11.220 -l
Logging in to [iface: default, target: iqn-2018-01-17.yuki.rhce:disk, portal: 10.2.11.220,3260] (multiple)
iscsiadm: Could not login to [iface: default, target: iqn-2018-01-17.yuki.rhce:disk, portal: 10.2.11.220,3260].
iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)
iscsiadm: Could not log into all portals
(如果沒有配置用戶名和密碼,則就沒辦法連接iscsi服務器)
配置/etc/iscsi/iscsi.conf
# *************
# CHAP Settings
# *************
# To enable CHAP authentication set node.session.auth.authmethod
# to CHAP. The default is None.
#node.session.auth.authmethod = CHAP
# To set a CHAP username and password for initiator
# authentication by the target(s), uncomment the following lines:
node.session.auth.username = tom
node.session.auth.password = redhat
[root@node2 ~]# iscsiadm -m discovery -t st -p 10.2.11.220
10.2.11.220:3260,1 iqn-2018-01-17.yuki.rhce:disk
[root@node2 ~]# iscsiadm -m node -T iqn-2018-01-17.yuki.rhce:disk -p 10.2.11.220 -l
Logging in to [iface: default, target: iqn-2018-01-17.yuki.rhce:disk, portal: 10.2.11.220,3260] (multiple)
Login to [iface: default, target: iqn-2018-01-17.yuki.rhce:disk, portal: 10.2.11.220,3260] successful.
- 第一章:集群理論介紹
- 第二章:共享存儲
- 第一節:搭建基于 IP SAN 的 ISCSI 存儲系統(在centos6系統)
- 第二節:基于openfiler搭建共享存儲
- 第三章:高可用HA集群
- 第一節:Heartbeat高可用集群
- 第二節:corosync+pacemaker高可用nginx集群
- 第四章:反向代理(負載均衡)集群
- 第一部分:haproxy服務
- 第一節:haproxy基本介紹
- 第二節:在Centos7安裝HAProxy
- 第三節: haproxy配置文件參數詳解
- 第四節:haproxy+nginx+mysql+discuz
- 第五節:haproxy配置文件
- 第六節: Haproxy搭建全站ssl