搭建系统架构
系统网络架构图
配置虚机3的目的是为了将来测试Oracle RAC,本实验可以不配。
配置虚机的linux网卡
每个虚机配3个网卡,一个通过桥接方式经vmware workstation虚拟交换机VMnet0连到外网;另两个网卡使用静态IP通过VMnet1与宿主机相连,这两个网卡用于配置两个iscsi路径。由于桥接方式的网卡IP地址是DHCP,不稳定,所以需要配置两个使用静态IP的网卡,方便实验操作。
虚机运行CentOS 6.8操作系统, 两块网卡设备文件名分别是目录/etc/sysconfig/network-scripts下的eth0和eth1。配置文件示例如下:
ifcfg-eth0
DEVICE=”eth0″
BOOTPROTO=”dhcp”
#HWADDR=”00:0C:29:C1:DF:AD”
IPV6INIT=”yes”
NM_CONTROLLED=”yes”
ONBOOT=”yes”
TYPE=”Ethernet”
#UUID=”aef56469-21c6-4b64-b1d3-d9263706e94a”
ifcfg-eth1
DEVICE=”eth1″
BOOTPROTO=”static”
HWADDR=”00:50:56:2E:77:86″
IPADDR=”192.168.136.101″
NETMASK=”255.255.255.0″
IPV6INIT=”yes”
NM_CONTROLLED=”yes”
ONBOOT=”yes”
TYPE=”Ethernet”
#UUID=”aef56469-21c6-4b64-b1d3-d9263706e94a”
ifcfg-eth2
DEVICE=”eth2″
BOOTPROTO=”static”
HWADDR=”00:0C:29:21:32:7B”
IPADDR=”192.168.20.101″
NETMASK=”255.255.255.0″
NM_CONTROLLED=”yes”
ONBOOT=”yes”
TYPE=”Ethernet”
#UUID=”c3c6c1c1-9480-42ae-8bca-05468b021895″
虚机的linux网卡配置文件修改后可以通过如下几种方式让它生效
1. 重新导入ifcfg-eth0网络配置文件
[root@linuxidc]#/etc/init.d/network reload
2. 网卡接口关闭与激活
[root@linuxidc]#ifdown eth0 #关闭网络
[root@linuxidc]#ifup eth0 #启动网络
3. 网络服务启动与关闭
方法一:
[root@localhost~]# service network stop #关闭网络服务
[root@localhost~]# service network start #启动网络服务
[root@localhost~]# service network restart #重启网络服务
方法二:
[root@localhost~]# /etc/init.d/network stop
[root@localhost~]# /etc/init.d/network start
[root@localhost~]# /etc/init.d/network restart
用如下命令可以查询网卡状态
[root@localhost~]# service network status
[root@localhost ~]# ifconfig
修改虚机的linux主机名和命令行提示符
-
1. 编辑 /etc/sysconfig/network文件,参考如下:
NETWORKING=yes
HOSTNAME=centos-i1
-
2. 编辑/etc/hosts文件,参考如下:
#127.0.0.1 localhost localhost.localdomain localhost4localhost4.localdomain4
127.0.0.1 centos-i1 centos-i1
::1 localhost localhost.localdomainlocalhost6 localhost6.localdomain6
-
3. 检查主机名设置
# Uname –a
# hostname
#ping centos-i1
上述修改结束之后,重新登录系统,命令行提示符就会显示正确的主机名,如果不是这样,设置环境变量PS1如下即可:
#export PS1='[/u@/h /W/]/$ ‘
其中 /u显示当前用户账号
/h显示当前主机名
/W显示当前路径(大写W为相对路径,小写w为绝对路径)
/$显示’$’符号
三个虚拟机的主机名及IP地址分配
主机名 |
Host only IP 1 |
Host only IP 2 |
Centos-i1 |
192.168.136.101 |
192.168.20.101 |
Centos-i2 |
192.168.136.102 |
192.168.20.102 |
Centos-i3 |
192.168.136.103 |
192.168.20.103 |
编辑/etc/hosts文件,加入以下三行:
192.168.136.101centos-i1
192.168.136.102centos-i2
192.168.136.103centos-i3
更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2017-04/142646p2.htm
安装iscsi软件
yum -y installscsi-target-utils (target软件包)(还有其它类似的软件包,这里选择最常用的)
yum -y installiscsi-initiator-utils (initiator软件包)
配置ISCSI target
注意:配置iscsi target的最佳文档是scsi-target-utils软件包的README.iscsi文件,在目录/usr/share/doc/scsi-target-utils-1.0.24下。
启动iscsi target服务进程
# service tgtd start
配置ISCSI target服务
进程启动后会读配置文件/etc/tgt/targets.conf,把文件中设置的ISCSI target服务配置项启动。文件中的配置项也可以手动启动,为了更好的理解target配置,我们先用命令行手工配置target服务
用tgtadm命令手工配置target服务
1. 配置target1
注意:不可以配置target0,原因不详
#tgtadm –lld iscsi –op new –mode target–tid 1 -T iqn.2017-03.CentOS-i1:sdb1
#tgtadm –lld iscsi –op delete –mode target–tid 2
2. 查看已经配置的target1
# tgtadm –lld iscsi –op show –modetarget
Target 1: iqn.2017-03.centos-i1:sdb1
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:
可以看到LUN0在target创立后即自动生成,用于控制命令的传输,不可以删除
1. 增加数据LUN
#tgtadm –lld iscsi –op new –mode logicalunit–tid 1 –lun 1 –backing-store /dev/sdb1
#tgtadm –lld iscsi –op delete –mode logicalunit–tid 1 –lun 1
2. 查看已经配置的LUN
# tgtadm –lld iscsi–op show –mode target
Target 1: iqn.2017-03.centos-i1:sdb1
System information:
Driver: iscsi
State: ready
I_Tnexus information:
LUNinformation:
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:
3. 配置target,以接受initiators的访问请求
#tgtadm –lld iscsi –op bind –mode target–tid 1 -I ALL
#tgtadm –lld iscsi–op unbind –mode target –tid 1 -I ALL
#tgtadm –lld iscsi–op bind –mode target –tid 1 -I 192.168.136.101/103
#tgtadm –lld iscsi–op bind –mode target –tid 1 -I 192.168.136.101
#tgtadm –lld iscsi–op bind –mode target –tid 1 -I 192.168.136.102
#tgtadm –lld iscsi–op bind –mode target –tid 1 -I 192.168.136.103
4. 查看target的访问请求控制
# tgtadm –lld iscsi –op show –mode target
Target 1: iqn.2017-03.centos-i1:sdb1
System information:
Driver: iscsi
State: ready
I_Tnexus information:
LUNinformation:
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:
ACLinformation: 这里是关键点
192.168.136.101/103
192.0.2.229
ALL
5. 查看并配置ISCSI Target的参数
#tgtadm –lld iscsi –mode target –opupdate –tid 1 –name MaxRecvDataSegmentLength –value 16384
# tgtadm –lld iscsi –op show –mode target –tid 1
MaxRecvDataSegmentLength=16384
MaxXmitDataSegmentLength=8192
HeaderDigest=None
DataDigest=None
InitialR2T=Yes
MaxOutstandingR2T=1
ImmediateData=Yes
FirstBurstLength=65536
MaxBurstLength=262144
DataPDUInOrder=Yes
DataSequenceInOrder=Yes
ErrorRecoveryLevel=0
IFMarker=No
OFMarker=No
DefaultTime2Wait=2
DefaultTime2Retain=20
OFMarkInt=Reject
IFMarkInt=Reject
MaxConnections=1
RDMAExtensions=Yes
TargetRecvDataSegmentLength=262144
InitiatorRecvDataSegmentLength=262144
MaxOutstandingUnexpectedPDUs=0
# tgtadm –lld iscsi –op show –mode target –tid 1
MaxRecvDataSegmentLength=8192
MaxXmitDataSegmentLength=8192
HeaderDigest=None
DataDigest=None
InitialR2T=Yes
MaxOutstandingR2T=1
ImmediateData=Yes
FirstBurstLength=65536
MaxBurstLength=262144
DataPDUInOrder=Yes
DataSequenceInOrder=Yes
ErrorRecoveryLevel=0
IFMarker=No
OFMarker=No
DefaultTime2Wait=2
DefaultTime2Retain=20
OFMarkInt=Reject
IFMarkInt=Reject
MaxConnections=1
RDMAExtensions=Yes
TargetRecvDataSegmentLength=262144
InitiatorRecvDataSegmentLength=262144
MaxOutstandingUnexpectedPDUs=0
6. 其它内容,比如查看连接的initiator信息,用户名/密码
查看/usr/share/doc/scsi-target-utils-1.0.24/README.iscsi文件
编辑/etc/tgt/targets.conf文件永久配置target服务
1. 编辑文件targets.conf,在文件尾部加入以下核心内容
<targetiqn.2017-03.centos-i1:target1>
backing-store /dev/sdb
# initiator-address ALL
initiator-address 192.168.136.101
initiator-address 192.168.136.102
initiator-address 192.168.136.103
initiator-address 192.168.20.101
initiator-address 192.168.20.102
initiator-address 192.168.20.103
vendor_id lb
product_id lb_iscsi
product_rev 01
</target>
#注意:上面配置的是接受所有initiator的IO,在手册上这本是缺省行为,但是我的实验环境中却偶然遇到必须在文件中显式制定才行,否则就不接受所有的initiator IO!
2. 重启tgtd服务
# service tgtd restart
Stopping SCSI targetdaemon: [ OK ]
Starting SCSI targetdaemon: [ OK ]
3. 检查target服务配置
下面两条命令看到的内容是一致的。
# tgt-admin -show
# tgtadm –lld iscsi –op show–mode target
Tgt-admmin是linux SCSI target配置工具;Tgtadm是linux SCSI target管理工具。tgt-admin调用tgtadm来创建、删除和显示target。总体而言,tgtadm功能更加强大,但是tgt-admin在配置target方面有独有的优点。
配置initiator端
-
1. 在initiator主机上安装initiator软件
# yum -y install iscsi-initiator-utils
-
2. 在initiator主机上发现并连接target存储
# iscsiadm -m discovery -t sendtargets -p192.168.136.101
#发现的target服务,信息会写入/var/lib/iscsi 目录下
# tree /var/lib/iscsi/ #查看target信息
-
3. 启动iscsid 服务
# /etc/init.d/iscsid start #先启动iscsid 服务
# /etc/init.d/iscsi start #再启动iscsi服务 该服务是根据iscsid服务信息/var/lib/iscsi/ 来识别设备的
-
4. 在initiator主机上检查分配给iscsi target设备的设备文件名
# lsblk
# tree /var/lib/iscsi/
检查iscsi磁盘配置, 以及卸载和登录scsi设备
# lsblk
# tree /var/lib/iscsi/
# iscsiadm -m node -Tiqn.2017-03.CentOS-i1:target1 –u #卸载,这里的案例是双路径
Logging out of session[sid: 1, target: iqn.2017-03.centos-i1:target1, portal: 192.168.20.101,3260]
Logging out of session[sid: 2, target: iqn.2017-03.centos-i1:target1, portal: 192.168.136.101,3260]
Logout of [sid: 1, target:iqn.2017-03.centos-i1:target1, portal: 192.168.20.101,3260] successful.
Logout of [sid: 2, target:iqn.2017-03.centos-i1:target1, portal: 192.168.136.101,3260] successful.
# lsblk #验证设备是否logout
# iscsiadm -m node -Tiqn.2017-03.centos-i1:target1 –l #重新登录,这里的案例是双路径
Logging in to [iface:default, target: iqn.2017-03.centos-i1:target1, portal: 192.168.20.101,3260](multiple)
Logging in to [iface:default, target: iqn.2017-03.centos-i1:target1, portal: 192.168.136.101,3260](multiple)
Login to [iface: default,target: iqn.2017-03.centos-i1:target1, portal: 192.168.20.101,3260] successful.
Login to [iface: default,target: iqn.2017-03.centos-i1:target1, portal: 192.168.136.101,3260]successful.
使用iscsi设备,并做写入操作测试
-
1. 磁盘分区(方法二选一)
# fdisk /dev/sdb
# parted /dev/sdb
-
2. 建文件系统并使用
# mkfs.ext4 /dev/sdb1
# mkdir /iscsi #挂载分区 到新建目录/iscsi
# mount /dev/sdb1 /iscsi/
# cp /home/lb/fio* /iscsi
在实验过程中,遇到如果在target端做过sdb分区,initiator看不到分区的情况。需要按照target端的参数重新分区,才看到分区里的数据。
安装与配置DM-multipath
安装运行DM软件
# yum install device-mapper-multipath
# /etc/init.d/multipathdrestart
ok
Stopping multipathddaemon: [ OK ]
Starting multipathddaemon: [ OK ]
Multipathd服务启动后,会通过SCSI ID自动寻找同一设备的多条路径,并安装缺省设置把它们聚合起来使用。
# multipath -ll
mpathb (1IET 00010001) dm-3 lb,lb_iscsi #’1IET 00010001′表示远程设备信息(CentOS6.5的DM multipath 0.4.9用它作为SCSI ID) dm-3 lb 表示厂商 lb_iscsi产品信息 这种情况就可以实现单点故障切换
size=5.0G features=’0’hwhandler=’0′ wp=rw
|-+- policy=’round-robin 0’prio=1 status=active #status=active 默认使用的链路
| `- 3:0:0:1 sdb 8:16 activeready running
`-+- policy=’round-robin 0’prio=1 status=enabled #status=enabled有效链路,但是不是活动链路,备用链路
`- 4:0:0:1 sdd 8:48 active ready running
配置multipath
2.1修改文件/etc/multipath.conf
默认情况下/etc目录下没有配置文件multipath.conf的。需要从/usr/share/doc/目录下拷贝过来使用。
#cp/usr/share/doc/device-mapper-multipath-0.4.9/multipath.conf /etc/
可以用man multipath.conf命令或者查看文件/usr/share/doc/device-mapper-multipath-0.4.9/multipath.conf.annotated了解配置选项的解释。
在此,通过在文件中加入下列配置行,我们为SCSI ID为“1IET 00010001”的设备设置了round-robin负载均衡模式(缺省是active-standby模式)
multipaths {
multipath {
wwid “1IET 00010001”
alias yellow
path_grouping_policy multibus
path_selector “round-robin 0”
failback manual
rr_weight priorities
no_path_retry 5
}
2.2重启multipathd服务,让修改生效
# /etc/init.d/multipathdrestart
# /etc/init.d/iscsirestart #实战发现必须做这一步,否则有问题,原因待查
验证multpath配置
# multipath -ll
yellow (1IET 00010001) dm-2 lb,lb_iscsi
size=10G features=’1queue_if_no_path’ hwhandler=’0′ wp=rw
`-+- policy=’round-robin 0’prio=1 status=active
|- 6:0:0:1 sdc 8:32 active ready running #在此可以看到设备都是active状态
`- 5:0:0:1 sdb 8:16 active ready running #在此可以看到设备都是active状态
模拟网卡故障,验证multipath的failover功能
# ifdown eth2 #执行后需要等几秒让DM确认该IP路径down掉
Device state: 3(disconnected)
# multipath -ll
Mar 23 17:12:21 |/etc/multipath.conf line 67, invalid keyword: path_checker
yellow (1IET 00010001) dm-2 lb,lb_iscsi
size=10G features=’1queue_if_no_path’ hwhandler=’0′ wp=rw
`-+- policy=’round-robin 0′ prio=1status=active
|- 7:0:0:1 sdd 8:48 active faulty running
`- 8:0:0:1 sdc 8:32 active ready running
# ifup eth2
Active connection state:activated
Active connection path:/org/freedesktop/NetworkManager/ActiveConnection/3
# multipath -ll
Mar 23 17:15:43 |/etc/multipath.conf line 67, invalid keyword: path_checker
yellow (1IET 00010001) dm-2 lb,lb_iscsi
size=10G features=’1queue_if_no_path’ hwhandler=’0′ wp=rw
`-+- policy=’round-robin 0’prio=1 status=active
|- 7:0:0:1 sdd 8:48 failed ready running
`- 8:0:0:1 sdc 8:32 active ready running
# sleep 60 #等待60秒
# multipath –ll #此时路径恢复
Mar 23 17:17:05 |/etc/multipath.conf line 67, invalid keyword: path_checker
yellow (1IET 00010001) dm-2 lb,lb_iscsi
size=10G features=’1 queue_if_no_path’hwhandler=’0′ wp=rw
`-+- policy=’round-robin 0’prio=1 status=active
|- 7:0:0:1 sdd 8:48 active ready running
`- 8:0:0:1 sdc 8:32 active readyrunning
Linux multipath与SCSI ID
Scsi_id命令包含在udev程序包中,可以在multipath.conf中配置该程序来获取scsi设备的SCSI ID。通过SCSI ID,便可以判断多个路径对应了同一设备。这个是多路径实现的关键。scsi_id是通过sg驱动,向设备发送EVPD page80或page83 的inquery命令来查询scsi设备的标识。但一些设备并不支持EVPD 的inquery命令,所以他们无法被用来生成multipath设备。如果这样,据说可以手工改写scsi_id,为不能提供scsi设备标识的设备虚拟一个标识符,并输出到标准输出,但是改写SCSI ID的方法不详。
multipath程序在创建multipath设备时,会调用scsi_id,从其标准输出中获得该设备的scsi id。
-
1. 几个查看SCSI设备详细信息的命令
l cat /proc/scsi/scsi
[root@CentOS-i2lb]# cat /proc/scsi/scsi
Attacheddevices:
Host: scsi1Channel: 00 Id: 00 Lun: 00
Vendor: NECVMWar Model: VMware IDE CDR10 Rev:1.00
Type: CD-ROM ANSI SCSI revision: 05
Host: scsi2Channel: 00 Id: 00 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi6Channel: 00 Id: 00 Lun: 00
Vendor: IET Model: Controller Rev: 0001
Type: RAID ANSI SCSI revision: 05
Host: scsi5Channel: 00 Id: 00 Lun: 00
Vendor: IET Model: Controller Rev: 0001
Type: RAID ANSI SCSI revision: 05
Host: scsi5Channel: 00 Id: 00 Lun: 01
Vendor: lb Model: lb_iscsi Rev: 01
Type: Direct-Access ANSI SCSI revision: 05
Host: scsi6Channel: 00 Id: 00 Lun: 01
Vendor: lb Model: lb_iscsi Rev: 01
Type: Direct-Access ANSI SCSI revision: 05
-
Lsscsi工具(需要安装)
[root@centos-i2lb]# lsscsi -v
[1:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0
dir: /sys/bus/scsi/devices/1:0:0:0 [/sys/devices/pci0000:00/0000:00:07.1/host1/target1:0:0/1:0:0:0]
[2:0:0:0] disk VMware, VMware Virtual S 1.0 /dev/sda
dir: /sys/bus/scsi/devices/2:0:0:0 [/sys/devices/pci0000:00/0000:00:10.0/host2/target2:0:0/2:0:0:0]
[5:0:0:0] storage IET Controller 0001 –
dir: /sys/bus/scsi/devices/5:0:0:0 [/sys/devices/platform/host5/session3/target5:0:0/5:0:0:0]
[5:0:0:1] disk lb lb_iscsi 01 /dev/sdb
dir: /sys/bus/scsi/devices/5:0:0:1 [/sys/devices/platform/host5/session3/target5:0:0/5:0:0:1]
[6:0:0:0] storage IET Controller 0001 –
dir: /sys/bus/scsi/devices/6:0:0:0 [/sys/devices/platform/host6/session4/target6:0:0/6:0:0:0]
[6:0:0:1] disk lb lb_iscsi 01 /dev/sdc
dir: /sys/bus/scsi/devices/6:0:0:1 [/sys/devices/platform/host6/session4/target6:0:0/6:0:0:1]
l ls –rtl /dev/disk/by-id
[root@centos-i2lb]# ls -rtl /dev/disk/by-id
total 0
lrwxrwxrwx. 1root root 9 Apr 7 13:16ata-VMware_Virtual_IDE_CDROM_Drive_10000000000000000001 -> ../../sr0
lrwxrwxrwx. 1root root 10 Apr 7 13:16lvm-pv-uuid-K3FudW-pVbU-3CxO-vYbz-JQgt-7cMD-trWZfc -> ../../sda2
lrwxrwxrwx. 1root root 10 Apr 7 13:16dm-uuid-LVM-6OQeAXlfx14VazFp21YfwgbtSE3P0IH1BMNhZdogpE93EoKvCxT3KZcCAqVmjG6M-> ../../dm-1
lrwxrwxrwx. 1root root 10 Apr 7 13:16dm-name-vg_centosi2-lv_swap -> ../../dm-1
lrwxrwxrwx. 1root root 10 Apr 7 13:16dm-uuid-LVM-6OQeAXlfx14VazFp21YfwgbtSE3P0IH129JpYlBs33F2gS64l2eNyeeIasmtvu2O-> ../../dm-0
lrwxrwxrwx. 1root root 10 Apr 7 13:16dm-name-vg_centosi2-lv_root -> ../../dm-0
lrwxrwxrwx. 1root root 9 Apr 7 13:28 scsi-1IET_00010001 -> ../../sdb
lrwxrwxrwx. 1root root 10 Apr 7 13:28dm-uuid-mpath-1IET\x20\x20\x20\x20\x2000010001 -> ../../dm-2
lrwxrwxrwx. 1root root 10 Apr 7 13:28 dm-name-yellow-> ../../dm-2
lrwxrwxrwx. 1root root 10 Apr 7 13:28dm-uuid-part1-mpath-1IET\x20\x20\x20\x20\x2000010001 -> ../../dm-3
lrwxrwxrwx. 1root root 10 Apr 7 13:28dm-name-yellowp1 -> ../../dm-3
-
ls –rtl /dev/disk/by-id
[root@centos-i2lb]# ls -rtl /dev/disk/by-path
total 0
lrwxrwxrwx. 1root root 9 Apr 7 13:16 pci-0000:00:10.0-scsi-0:0:0:0 ->../../sda
lrwxrwxrwx. 1root root 9 Apr 7 13:16 pci-0000:00:07.1-scsi-1:0:0:0 ->../../sr0
lrwxrwxrwx. 1root root 10 Apr 7 13:16pci-0000:00:10.0-scsi-0:0:0:0-part2 -> ../../sda2
lrwxrwxrwx. 1root root 10 Apr 7 13:16pci-0000:00:10.0-scsi-0:0:0:0-part1 -> ../../sda1
lrwxrwxrwx. 1root root 9 Apr 7 13:28ip-192.168.136.101:3260-iscsi-iqn.2017-03.centos-i1:target1-lun-1 ->../../sdc
lrwxrwxrwx. 1root root 9 Apr 7 13:28ip-192.168.20.101:3260-iscsi-iqn.2017-03.centos-i1:target1-lun-1 ->../../sdb
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-04/142646.htm