环境: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