多路径软件是为了解决单路径一对一的单点故障而研发的,实现由主机到存储的多条链路通讯。如果存储服务器到主机或是交换机只有一条线路的时候,当这条线路出现故障时,整个系统就无法使用,所以使用多路径可以解决这个问题,避免点单故障。
多路径软件主要是配合存储一起使用,实现故障切换和恢复、IO流量负载均衡和硬盘的虚拟化操作。
在做DM multipath测试前需要配置存储,在这里我们使用上章节博客写的IP SAN存储设备。
测试服务器如下,另外需要安装DM multipath 多路径套件(device-mapper-multipath)
服务名称
服务器地址
服务端 :node01
192.168.137.101
客户端 :node02
192.168.137.102
使用vmvare模拟多路径,我们需要为虚拟机配置两张网卡,实现互通。在这里我们将node01配置服务端,将/dev/sdb1 通过ip scan共享。
在博客http://blog.itpub.net/27039319/viewspace-2123341/基础上编辑/etc/tgt/targets.conf文件,增加新建立网卡地址192.168.20.XXX。内容如下
1.修改服务端node01的tgt服务
点击(此处)折叠或打开
[root@node01 network-scripts]# vi /etc/tgt/targets.conf
backing-store /dev/sdb1
initiator-address 192.168.137.102
initiator-address 192.168.20.102
vendor_id node
product_id target4
[root@node01 network-scripts]# service tgtd restart
Stopping SCSI target daemon: [ OK ]
Starting SCSI target daemon: [ OK ]
[root@node01 ~]# tgt-admin -show
Target 1: iqn.2016-08.cn.node01.www:target4_scan
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: 5379 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:
Account information:
ACL information:
192.168.137.102
192.168.20.102
[root@node01 ~]#
2. 在客户端node02上增加 192.168.20.101线路,这样就与192.168.137.101 实现双线路
点击(此处)折叠或打开
[root@node02 ~]# iscsiadm -m discovery -t st -p 192.168.20.101:3260 #增加新线路192.168.20.101 ,添加成功
192.168.20.101:3260,1 iqn.2016-08.cn.node01.www:target4_scan
[root@node02 ~]# lsblk #查看块信息 并无其他新信息
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 10G 0 part /
└─sda3 8:3 0 1G 0 part [SWAP]
sr0 11:0 1 3.6G 0 rom
sdb 8:16 0 5G 0 disk
└─sdb1 8:17 0 5G 0 part
[root@node02 ~]# tree /var/lib/iscsi/ #查看/var/lib/iscsi 目录信息,发现新增加的192.168.20.101线路信息
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
│ └── iqn.2016-08.cn.node01.www:target4_scan
│ ├── 192.168.137.101,3260,1
│ │ └── default
│ └── 192.168.20.101,3260,1
│ └── default
├── send_targets
│ ├── 192.168.137.101,3260
│ │ ├── iqn.2016-08.cn.node01.www:target4_scan,192.168.137.101,3260,1,default -> /var/lib/iscsi/nodes/iqn.2016-08.cn.node01.www:target4_scan/192.168.137.101,3260,1
│ │ └── st_config
│ └── 192.168.20.101,3260
│ ├── iqn.2016-08.cn.node01.www:target4_scan,192.168.20.101,3260,1,default -> /var/lib/iscsi/nodes/iqn.2016-08.cn.node01.www:target4_scan/192.168.20.101,3260,1
│ └── st_config
├── slp
└── static
13 directories, 4 files
[root@node02 ~]# /etc/init.d/iscsi restart #restart iscsi服务
Stopping iscsi: [ OK ]
Starting iscsi: [ OK ]
[root@node02 ~]# lsblk #未分区,就看到新增 sdc1
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 10G 0 part /
└─sda3 8:3 0 1G 0 part [SWAP]
sr0 11:0 1 3.6G 0 rom
sdb 8:16 0 5G 0 disk
└─sdb1 8:17 0 5G 0 part
sdc 8:32 0 5G 0 disk
└─sdc1 8:33 0 5G 0 part
[root@node02 opt]# mount /dev/sdc1 /opt/
[root@node02 opt]# ll
total 0
[root@node02 opt]# cd /opt/ #挂载sdc1 可以看到上面博客中提到的信息。在node03上写入的passwd 文件
[root@node02 opt]# ll
total 40
-rw------- 1 root root 980 Aug 12 00:59 anaconda-ks.cfg
-rw-r--r-- 1 root root 10197 Aug 12 00:59 install.log
-rw-r--r-- 1 root root 3161 Aug 12 00:59 install.log.syslog
drwx------ 2 root root 16384 Aug 12 00:58 lost+found
-rw-r--r-- 1 root root 901 Aug 12 01:11 passwd
[root@node02 opt]#
[root@node02 ~]#
########在服务端查看3260端口信息 发现新线路192.168.20.101 #######
[root@node01 ~]# netstat -antup |grep 3260
tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN 1028/tgtd
tcp 0 0 192.168.137.101:3260 192.168.137.102:58788 ESTABLISHED 1028/tgtd
tcp 0 0 192.168.20.101:3260 192.168.20.102:57592 ESTABLISHED 1028/tgtd
tcp 0 0 :::3260 :::* LISTEN 1028/tgtd
[root@node01 ~]#
3 配置multipath 多路径软件,配置多路径冗余模式
点击(此处)折叠或打开
[root@node02 opt]# yum -y install device-mapper-multipath #安装软件
[root@node02 opt]# cp /usr/share/doc/device-mapper-multipath-0.4.9/multipath.conf /etc/ #默认情况下 无配置文件的。需要从/usr/share/doc/目录下拷贝
[root@node02 opt]# /etc/init.d/multipathd restart #启动软件
ux_socket_connect: No such file or directory
Stopping multipathd daemon: [FAILED]
Starting multipathd daemon: [ OK ]
[root@node02 opt]#
[root@node02 opt]# multipath -ll #未发现多路径信息 这里需要把原有mount的卸载
[root@node02 opt]#
[root@node02 opt]# umount /opt/
umount: /opt: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@node02 opt]# cd
[root@node02 ~]# umount /opt/
[root@node02 ~]# multipath -ll
[root@node02 ~]# /etc/init.d/multipathd restart #卸载后重启 发现多路径信息
ok
Stopping multipathd daemon: [ OK ]
Starting multipathd daemon: [ OK ]
[root@node02 ~]# multipath -ll
mpatha (1IET 00010001) dm-0 node,target4 #'1IET 00010001'表示远程设备信息 dm-0 node 表示厂商 target4 产品信息 这种情况就可以实现单点故障切换
size=5.0G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=1 status=active #status=active 默认使用的链路
| `- 36:0:0:1 sdb 8:16 active ready running
`-+- policy='round-robin 0' prio=1 status=enabled #status=enabled 有效链路,但是不是活动链路
`- 35:0:0:1 sdc 8:32 active ready running
[root@node02 ~]#
[root@node02 ~]# ll /dev/mapper/ #设备文件 /dev/mapper/mpatha ,生成dm设备
total 0
crw-rw---- 1 root root 10, 57 Aug 12 17:26 control
lrwxrwxrwx 1 root root 7 Aug 12 18:36 mpatha -> ../dm-0
lrwxrwxrwx 1 root root 7 Aug 12 18:36 mpathap1 -> ../dm-1
[root@node02 ~]# mount /dev/mapper/mpathap1 /opt/ #挂载mpathap1 存储可用
[root@node02 ~]# ll !$
ll /opt/
total 40
-rw------- 1 root root 980 Aug 12 00:59 anaconda-ks.cfg
-rw-r--r-- 1 root root 10197 Aug 12 00:59 install.log
-rw-r--r-- 1 root root 3161 Aug 12 00:59 install.log.syslog
drwx------ 2 root root 16384 Aug 12 00:58 lost+found
-rw-r--r-- 1 root root 901 Aug 12 01:11 passwd
[root@node02 opt]# rm passwd
rm: remove regular file `passwd'? yes
[root@node02 opt]# ll
total 36
-rw------- 1 root root 980 Aug 12 00:59 anaconda-ks.cfg
-rw-r--r-- 1 root root 10197 Aug 12 00:59 install.log
-rw-r--r-- 1 root root 3161 Aug 12 00:59 install.log.syslog
drwx------ 2 root root 16384 Aug 12 00:58 lost+found
[root@node02 opt]#
4. 配置负载模式 编辑/etc/multipath.conf 文件,修改如下信息
点击(此处)折叠或打开
[root@node02 opt]#vim /etc/multipath.conf
multipaths {
multipath {
wwid"1IET 00010001" #wwid 可以通过scsi_id生成 同时也multipath -ll 看到mpatha (1IET 00010001)远程存储信息
alias yellow #dm 别名 ,可以随便修改
path_grouping_policy multibus
path_checker readsector0
path_selector"round-robin 0"
failback manual
rr_weight priorities #权重信息
no_path_retry 5
}
}
[root@node02 ~]# /lib/udev/scsi_id --page=0x83 --whitelisted --device=/dev/sdb #生成wwid
1IET 00010001
[root@node02 ~]# /lib/udev/scsi_id --page=0x83 --whitelisted --device=/dev/sdc
1IET 00010001
[root@node02 ~]# multipath -ll
Aug 12 19:26:35 | multipath.conf line 67, invalid keyword: path_checker
mpatha (1IET 00010001) dm-0 node,target4
size=5.0G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=1 status=active
| `- 36:0:0:1 sdb 8:16 active ready running
`-+- policy='round-robin 0' prio=1 status=enabled
`- 35:0:0:1 sdc 8:32 active ready running
[root@node02 ~]#
[root@node02 opt]# /etc/init.d/multipathd restart #重启multipath服务
ok
Stopping multipathd daemon: [ OK ]
Starting multipathd daemon: [ OK ]
[root@node02 opt]# /etc/init.d/iscsi restart #重启 识别scsi
Stopping iscsi: [ OK ]
Starting iscsi: [ OK ]
[root@node02 opt]# multipath -ll
Aug 12 20:05:52 | multipath.conf line 67, invalid keyword: path_checker
yellow (1IET 00010001) dm-0 node,target4
size=5.0G features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=1 status=active #启用负载均衡模式
|- 38:0:0:1 sdb 8:16 active ready running
`- 37:0:0:1 sdc 8:32 active ready running
[root@node02 opt]#
[root@node02 opt]# ll /dev/mapper/ #查看/dev/mapper 下的设备信息 由原来的mpathp 变更为multipath.conf 文件中更新的别名 yellow了
total 0
crw-rw---- 1 root root 10, 57 Aug 12 17:26 control
lrwxrwxrwx 1 root root 7 Aug 12 20:05 yellow -> ../dm-0
lrwxrwxrwx 1 root root 7 Aug 12 20:05 yellowp1 -> ../dm-1
[root@node02 ~]# umount /opt/
[root@node02 ~]# mount /dev/mapper/yellowp1 /opt/ #重新挂载dm
[root@node02 ~]# cd !$
cd /opt/
[root@node02 opt]# ll
total 40
-rw------- 1 root root 980 Aug 12 00:59 anaconda-ks.cfg
-rw-r--r-- 1 root root 10197 Aug 12 00:59 install.log
-rw-r--r-- 1 root root 3161 Aug 12 00:59 install.log.syslog
drwx------ 2 root root 16384 Aug 12 00:58 lost+found
-rw-r--r-- 1 root root 901 Aug 12 20:08 passwd
[root@node02 opt]#
5. 模拟故障 ,分别关闭网卡eth0和eth1 看看链路高可用性,切换过程大概需要1分钟时间
点击(此处)折叠或打开
[root@node01 ~]# ifdown eth1
[root@node01 ~]#
[root@node02 opt]# multipath -ll
Aug 12 20:16:57 | multipath.conf line 67, invalid keyword: path_checker
yellow (1IET 00010001) dm-0 node,target4
size=5.0G features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=1 status=active
|- 38:0:0:1 sdb 8:16 failed faulty running #状态改变
`- 37:0:0:1 sdc 8:32 active ready running
[root@node02 opt]# ll
total 40
-rw------- 1 root root 980 Aug 12 00:59 anaconda-ks.cfg
-rw-r--r-- 1 root root 10197 Aug 12 00:59 install.log
-rw-r--r-- 1 root root 3161 Aug 12 00:59 install.log.syslog
drwx------ 2 root root 16384 Aug 12 00:58 lost+found
-rw-r--r-- 1 root root 901 Aug 12 20:08 passwd
[root@node02 opt]# cp /etc/localtime /opt/ #测试写入 正常
[root@node02 opt]# ll
total 44
-rw------- 1 root root 980 Aug 12 00:59 anaconda-ks.cfg
-rw-r--r-- 1 root root 10197 Aug 12 00:59 install.log
-rw-r--r-- 1 root root 3161 Aug 12 00:59 install.log.syslog
-rw-r--r-- 1 root root 405 Aug 12 20:17 localtime
drwx------ 2 root root 16384 Aug 12 00:58 lost+found
-rw-r--r-- 1 root root 901 Aug 12 20:08 passwd