Linux主机之存储多路径(multipath)配置
  

justgonnab 101852人觉得有帮助

{{ttag.title}}
本帖最后由 justgonnab 于 2018-9-29 11:57 编辑

Linux服务器架设在当今还是比较常见的,没有点基础的Linux必备开局方法还真是不行,好在像RHEL等商业化的Linux系统都自带了很多常用驱动,包括:网卡、USB、RAID、HBA等。所以在开局过程中可以事半功倍,节省很多时间而且可以使版本复杂的开源Linux系统稳定可靠运行,避免很多兼容性问题。

所以今天分享下Linux服务器架设中比较重要的一块工作:存储多路径配置。

操作系统环境:Red Hat Enterprise Linux Server release 6.5 (Santiago)

首先查看系统中是否安装了多路径软件:


微信截图_20180929104847.png

device-mapper-X.X.X-X.el6.x86_64
device-mapper-persistent-data-X.X.X-2.el6.x86_64
device-mapper-libs-X.X.X-X.el6.x86_64
device-mapper-event-X.X.X-X.el6.x86_64
device-mapper-multipath-libs-X.X.X-X.el6.x86_64
device-mapper-multipath-X.X.X-X.el6.x86_64
device-mapper-event-libs-X.X.X-X.el6.x86_64

如果查询结果缺少或没有上述的安装包,则执行下面的命令进行安装:
#yum –y install device-mapper device-mapper-multipath.x86_64 device-mapper-multipath-libs.x86_64

  1. [root@localhost ~]# <b>yum -y install device-mapper</b>
  2. Loaded plugins: fastestmirror
  3. base                                                                                                                                  | 3.7 kB     00:00     
  4. base/primary_db                                                                                                                       | 4.7 MB     00:01     
  5. extras                                                                                                                                | 3.4 kB     00:00     
  6. extras/primary_db                                                                                                                     |  26 kB     00:00     
  7. updates                                                                                                                               | 3.4 kB     00:00     
  8. updates/primary_db                                                                                                                    | 1.3 MB     00:00     
  9. Setting up Install Process
  10. Resolving Dependencies
  11. --> Running transaction check
  12. ---> Package device-mapper.x86_64 0:1.02.79-8.el6 will be updated
  13. --> Processing Dependency: device-mapper = 1.02.79-8.el6 for package: device-mapper-libs-1.02.79-8.el6.x86_64
  14. --> Processing Dependency: device-mapper = 1.02.79-8.el6 for package: device-mapper-event-1.02.79-8.el6.x86_64
  15. ---> Package device-mapper.x86_64 0:1.02.117-12.el6_9.1 will be an update
  16. --> Running transaction check
  17. ---> Package device-mapper-event.x86_64 0:1.02.79-8.el6 will be updated
  18. ---> Package device-mapper-event.x86_64 0:1.02.117-12.el6_9.1 will be an update
  19. --> Processing Dependency: device-mapper-event-libs = 1.02.117-12.el6_9.1 for package: device-mapper-event-1.02.117-12.el6_9.1.x86_64
  20. ---> Package device-mapper-libs.x86_64 0:1.02.79-8.el6 will be updated
  21. ---> Package device-mapper-libs.x86_64 0:1.02.117-12.el6_9.1 will be an update
  22. --> Running transaction check
  23. ---> Package device-mapper-event-libs.x86_64 0:1.02.79-8.el6 will be updated
  24. ---> Package device-mapper-event-libs.x86_64 0:1.02.117-12.el6_9.1 will be an update
  25. --> Processing Conflict: device-mapper-event-1.02.117-12.el6_9.1.x86_64 conflicts lvm2-libs < 2.02.111
  26. --> Restarting Dependency Resolution with new changes.
  27. --> Running transaction check
  28. ---> Package lvm2-libs.x86_64 0:2.02.100-8.el6 will be updated
  29. --> Processing Dependency: lvm2-libs = 2.02.100-8.el6 for package: lvm2-2.02.100-8.el6.x86_64
  30. ---> Package lvm2-libs.x86_64 0:2.02.143-12.el6_9.1 will be an update
  31. --> Running transaction check
  32. ---> Package lvm2.x86_64 0:2.02.100-8.el6 will be updated
  33. ---> Package lvm2.x86_64 0:2.02.143-12.el6_9.1 will be an update
  34. --> Processing Dependency: device-mapper-persistent-data >= 0.6.2 for package: lvm2-2.02.143-12.el6_9.1.x86_64
  35. --> Running transaction check
  36. ---> Package device-mapper-persistent-data.x86_64 0:0.2.8-2.el6 will be updated
  37. ---> Package device-mapper-persistent-data.x86_64 0:0.6.2-0.2.rc7.el6 will be an update
  38. --> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: device-mapper-persistent-data-0.6.2-0.2.rc7.el6.x86_64
  39. --> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: device-mapper-persistent-data-0.6.2-0.2.rc7.el6.x86_64
  40. --> Processing Dependency: libaio.so.1()(64bit) for package: device-mapper-persistent-data-0.6.2-0.2.rc7.el6.x86_64
  41. --> Running transaction check
  42. ---> Package libaio.x86_64 0:0.3.107-10.el6 will be installed
  43. --> Finished Dependency Resolution

  44. Dependencies Resolved

  45. =============================================================================================================================================================
  46. Package                                             Arch                         Version                                   Repository                  Size
  47. =============================================================================================================================================================
  48. Updating:
  49. device-mapper                                       x86_64                       1.02.117-12.el6_9.1                       base                       218 k
  50. lvm2-libs                                           x86_64                       2.02.143-12.el6_9.1                       base                       1.0 M
  51. Installing for dependencies:
  52. libaio                                              x86_64                       0.3.107-10.el6                            base                        21 k
  53. Updating for dependencies:
  54. device-mapper-event                                 x86_64                       1.02.117-12.el6_9.1                       base                       134 k
  55. device-mapper-event-libs                            x86_64                       1.02.117-12.el6_9.1                       base                       126 k
  56. device-mapper-libs                                  x86_64                       1.02.117-12.el6_9.1                       base                       257 k
  57. device-mapper-persistent-data                       x86_64                       0.6.2-0.2.rc7.el6                         base                       463 k
  58. lvm2                                                x86_64                       2.02.143-12.el6_9.1                       base                       941 k

  59. Transaction Summary
  60. =============================================================================================================================================================
  61. Install       1 Package(s)
  62. Upgrade       7 Package(s)

  63. Total download size: 3.1 M
  64. Downloading Packages:
  65. (1/8): device-mapper-1.02.117-12.el6_9.1.x86_64.rpm                                                                                   | 218 kB     00:00     
  66. (2/8): device-mapper-event-1.02.117-12.el6_9.1.x86_64.rpm                                                                             | 134 kB     00:00     
  67. (3/8): device-mapper-event-libs-1.02.117-12.el6_9.1.x86_64.rpm                                                                        | 126 kB     00:00     
  68. (4/8): device-mapper-libs-1.02.117-12.el6_9.1.x86_64.rpm                                                                              | 257 kB     00:00     
  69. (5/8): device-mapper-persistent-data-0.6.2-0.2.rc7.el6.x86_64.rpm                                                                     | 463 kB     00:00     
  70. (6/8): libaio-0.3.107-10.el6.x86_64.rpm                                                                                               |  21 kB     00:00     
  71. (7/8): lvm2-2.02.143-12.el6_9.1.x86_64.rpm                                                                                            | 941 kB     00:00     
  72. (8/8): lvm2-libs-2.02.143-12.el6_9.1.x86_64.rpm                                                                                       | 1.0 MB     00:00     
  73. -------------------------------------------------------------------------------------------------------------------------------------------------------------
  74. Total                                                                                                                        2.6 MB/s | 3.1 MB     00:01     
  75. warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
  76. Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
  77. Importing GPG key 0xC105B9DE:
  78. Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>
  79. Package: centos-release-6-5.el6.centos.11.1.x86_64 (@anaconda-CentOS-201311272149.x86_64/6.5)
  80. From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
  81. Running rpm_check_debug
  82. Running Transaction Test
  83. Transaction Test Succeeded
  84. Running Transaction
  85.   Updating   : device-mapper-1.02.117-12.el6_9.1.x86_64                                                                                                 1/15
  86.   Updating   : device-mapper-libs-1.02.117-12.el6_9.1.x86_64                                                                                            2/15
  87.   Updating   : device-mapper-event-libs-1.02.117-12.el6_9.1.x86_64                                                                                      3/15
  88.   Updating   : device-mapper-event-1.02.117-12.el6_9.1.x86_64                                                                                           4/15
  89.   Updating   : lvm2-libs-2.02.143-12.el6_9.1.x86_64                                                                                                     5/15
  90.   Installing : libaio-0.3.107-10.el6.x86_64                                                                                                             6/15
  91.   Updating   : device-mapper-persistent-data-0.6.2-0.2.rc7.el6.x86_64                                                                                   7/15
  92.   Updating   : lvm2-2.02.143-12.el6_9.1.x86_64                                                                                                          8/15
  93.   Cleanup    : lvm2-2.02.100-8.el6.x86_64                                                                                                               9/15
  94.   Cleanup    : lvm2-libs-2.02.100-8.el6.x86_64                                                                                                         10/15
  95.   Cleanup    : device-mapper-event-1.02.79-8.el6.x86_64                                                                                                11/15
  96.   Cleanup    : device-mapper-event-libs-1.02.79-8.el6.x86_64                                                                                           12/15
  97.   Cleanup    : device-mapper-1.02.79-8.el6.x86_64                                                                                                      13/15
  98.   Cleanup    : device-mapper-libs-1.02.79-8.el6.x86_64                                                                                                 14/15
  99.   Cleanup    : device-mapper-persistent-data-0.2.8-2.el6.x86_64                                                                                        15/15
  100.   Verifying  : device-mapper-persistent-data-0.6.2-0.2.rc7.el6.x86_64                                                                                   1/15
  101.   Verifying  : lvm2-libs-2.02.143-12.el6_9.1.x86_64                                                                                                     2/15
  102.   Verifying  : lvm2-2.02.143-12.el6_9.1.x86_64                                                                                                          3/15
  103.   Verifying  : device-mapper-libs-1.02.117-12.el6_9.1.x86_64                                                                                            4/15
  104.   Verifying  : device-mapper-event-1.02.117-12.el6_9.1.x86_64                                                                                           5/15
  105.   Verifying  : libaio-0.3.107-10.el6.x86_64                                                                                                             6/15
  106.   Verifying  : device-mapper-event-libs-1.02.117-12.el6_9.1.x86_64                                                                                      7/15
  107.   Verifying  : device-mapper-1.02.117-12.el6_9.1.x86_64                                                                                                 8/15
  108.   Verifying  : device-mapper-1.02.79-8.el6.x86_64                                                                                                       9/15
  109.   Verifying  : device-mapper-event-libs-1.02.79-8.el6.x86_64                                                                                           10/15
  110.   Verifying  : device-mapper-persistent-data-0.2.8-2.el6.x86_64                                                                                        11/15
  111.   Verifying  : device-mapper-event-1.02.79-8.el6.x86_64                                                                                                12/15
  112.   Verifying  : lvm2-libs-2.02.100-8.el6.x86_64                                                                                                         13/15
  113.   Verifying  : device-mapper-libs-1.02.79-8.el6.x86_64                                                                                                 14/15
  114.   Verifying  : lvm2-2.02.100-8.el6.x86_64                                                                                                              15/15

  115. Dependency Installed:
  116.   libaio.x86_64 0:0.3.107-10.el6                                                                                                                             

  117. Updated:
  118.   device-mapper.x86_64 0:1.02.117-12.el6_9.1                                      lvm2-libs.x86_64 0:2.02.143-12.el6_9.1                                    

  119. Dependency Updated:
  120.   device-mapper-event.x86_64 0:1.02.117-12.el6_9.1                          device-mapper-event-libs.x86_64 0:1.02.117-12.el6_9.1                           
  121.   device-mapper-libs.x86_64 0:1.02.117-12.el6_9.1                           device-mapper-persistent-data.x86_64 0:0.6.2-0.2.rc7.el6                        
  122.   lvm2.x86_64 0:2.02.143-12.el6_9.1                                       

  123. Complete!
复制代码
  1. [root@localhost ~]# <b>yum install device-mapper-multipath.x86_64 device-mapper-multipath-libs.x86_64</b>
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. * base: mirrors.aliyun.com
  5. * extras: mirrors.aliyun.com
  6. * updates: mirrors.aliyun.com
  7. Setting up Install Process
  8. Resolving Dependencies
  9. --> Running transaction check
  10. ---> Package device-mapper-multipath.x86_64 0:0.4.9-106.el6 will be installed
  11. --> Processing Dependency: kpartx = 0.4.9-106.el6 for package: device-mapper-multipath-0.4.9-106.el6.x86_64
  12. ---> Package device-mapper-multipath-libs.x86_64 0:0.4.9-106.el6 will be installed
  13. --> Running transaction check
  14. ---> Package kpartx.x86_64 0:0.4.9-106.el6 will be installed
  15. --> Finished Dependency Resolution

  16. Dependencies Resolved

  17. =============================================================================================================================================================
  18. Package                                             Arch                          Version                                 Repository                   Size
  19. =============================================================================================================================================================
  20. Installing:
  21. device-mapper-multipath                             x86_64                        0.4.9-106.el6                           base                        133 k
  22. device-mapper-multipath-libs                        x86_64                        0.4.9-106.el6                           base                        204 k
  23. Installing for dependencies:
  24. kpartx                                              x86_64                        0.4.9-106.el6                           base                         71 k

  25. Transaction Summary
  26. =============================================================================================================================================================
  27. Install       3 Package(s)

  28. Total download size: 409 k
  29. Installed size: 731 k
  30. Is this ok [y/N]: y
  31. Downloading Packages:
  32. (1/3): device-mapper-multipath-0.4.9-106.el6.x86_64.rpm                                                                               | 133 kB     00:00     
  33. (2/3): device-mapper-multipath-libs-0.4.9-106.el6.x86_64.rpm                                                                          | 204 kB     00:00     
  34. (3/3): kpartx-0.4.9-106.el6.x86_64.rpm                                                                                                |  71 kB     00:00     
  35. -------------------------------------------------------------------------------------------------------------------------------------------------------------
  36. Total                                                                                                                        1.0 MB/s | 409 kB     00:00     
  37. Running rpm_check_debug
  38. Running Transaction Test
  39. Transaction Test Succeeded
  40. Running Transaction
  41.   Installing : device-mapper-multipath-libs-0.4.9-106.el6.x86_64                                                                                         1/3
  42.   Installing : kpartx-0.4.9-106.el6.x86_64                                                                                                               2/3
  43.   Installing : device-mapper-multipath-0.4.9-106.el6.x86_64                                                                                              3/3
  44.   Verifying  : kpartx-0.4.9-106.el6.x86_64                                                                                                               1/3
  45.   Verifying  : device-mapper-multipath-libs-0.4.9-106.el6.x86_64                                                                                         2/3
  46.   Verifying  : device-mapper-multipath-0.4.9-106.el6.x86_64                                                                                              3/3

  47. Installed:
  48.   device-mapper-multipath.x86_64 0:0.4.9-106.el6                             device-mapper-multipath-libs.x86_64 0:0.4.9-106.el6                           

  49. Dependency Installed:
  50.   kpartx.x86_64 0:0.4.9-106.el6                                                                                                                              

  51. Complete!
复制代码
附:
如果服务器无法连接外网,则可以挂载本地镜像来进行安装。具体操作步骤如下:
使用xftp上传对应版本的操作系统ISO镜像到服务器本地(例如:放在/tmp目录下)
然后挂载本地镜像到/mnt目录:
[root@zxt-1 san]# mount /tmp/rhel-server-6.5-x86_64-dvd.iso /mnt/
接下来开始配置yum源:
在/etc/yum.repos.d/文件夹下创建源文件myyum.repo
编辑文件内容输入:
[myyum]

name=myyum is test  

baseurl=file:///mnt/

enabled=1

gpgcheck=0

创建yum缓存:
yum makecache

然后yum安装所需要的软件包即可。

安装完毕后记得卸载挂载的ISO文件:
umount /mnt

安装完毕后,查看多路径是否开机自启动:
# chkconfig --list|grep multipathd

设置开机自启动:
# chkconfig --level 2345 multipathd on

检查安装是否正常,内核中是否存在:
# modprobe -l|grep multipath
kernel/drivers/md/dm-multipath.ko

重启操作系统加载内核或手工进行加载:
# modprobe dm-multipath
# modprobe dm-round-robin
# service multipathd start

产生multipath配置文件
[root@oracle-bak ~]# /sbin/matchpathcon --enable


微信截图_20180929111801.png

一般情况下multipath.conf文件无需修改保持默认即可。

获取wwid查看是否识别硬盘:
#multipath -v3


微信截图_20180929112718.png

最后重启多路径:
#service multipathd restart

重启完毕后查看多路径是否生效:
#multipath -ll


微信截图_20180929112842.png

上述表明多路径建立成功,但是接下来通过fdisk命令来查看识别的磁盘:

  1. [root@oracle-bak ~]# fdisk -l

  2. ******省略部分内容******

  3. Disk <font color="#ff0000"><b>/dev/sdb</b></font>: 1024.0 GB, 1023997378560 bytes
  4. 255 heads, 63 sectors/track, 124493 cylinders
  5. Units = cylinders of 16065 * 512 = 8225280 bytes
  6. Sector size (logical/physical): 512 bytes / 512 bytes
  7. I/O size (minimum/optimal): 512 bytes / 1048576 bytes
  8. Disk identifier: 0x00000000


  9. Disk <b><font color="#ff0000">/dev/sdd</font></b>: 1024.0 GB, 1023997378560 bytes
  10. 255 heads, 63 sectors/track, 124493 cylinders
  11. Units = cylinders of 16065 * 512 = 8225280 bytes
  12. Sector size (logical/physical): 512 bytes / 512 bytes
  13. I/O size (minimum/optimal): 512 bytes / 1048576 bytes
  14. Disk identifier: 0x00000000


  15. Disk <b><font color="#ff0000">/dev/sde</font></b>: 1024.0 GB, 1023997378560 bytes
  16. 255 heads, 63 sectors/track, 124493 cylinders
  17. Units = cylinders of 16065 * 512 = 8225280 bytes
  18. Sector size (logical/physical): 512 bytes / 512 bytes
  19. I/O size (minimum/optimal): 512 bytes / 1048576 bytes
  20. Disk identifier: 0x00000000


  21. Disk<b><font color="#ff0000"> /dev/sdc</font></b>: 1024.0 GB, 1023997378560 bytes
  22. 255 heads, 63 sectors/track, 124493 cylinders
  23. Units = cylinders of 16065 * 512 = 8225280 bytes
  24. Sector size (logical/physical): 512 bytes / 512 bytes
  25. I/O size (minimum/optimal): 512 bytes / 1048576 bytes
  26. Disk identifier: 0x00000000


  27. Disk <font color="#ff0000"><b>/dev/mapper/mpathb</b></font>: 1024.0 GB, 1023997378560 bytes
  28. 255 heads, 63 sectors/track, 124493 cylinders
  29. Units = cylinders of 16065 * 512 = 8225280 bytes
  30. Sector size (logical/physical): 512 bytes / 512 bytes
  31. I/O size (minimum/optimal): 512 bytes / 1048576 bytes
  32. Disk identifier: 0x00000000
复制代码

这边会看到5块相同大小的磁盘,但是我们必须且只能挂载多路径生成的/dev/mapper/mpathb磁盘,其它4块盘sdb、sdc、sdd、sde是因为同一块映射的磁盘到主机侧有4条有效路径所以识别为4块盘,实质上都是同一个LUN映射出来的。如果挂载了其它的其中一块磁盘会发现读写正常但是其余磁盘数据无法同步,且无法实现存储链路冗余备份的作用,这也就是多路径真正的作用。

最终可以对/dev/mapper/mpathb直接进行挂载、格式化使用,或者也可以用来创建之前分享的文章所讲到的逻辑卷(LV)实现后期的磁盘可扩容。

打赏鼓励作者,期待更多好文!

打赏
3人已打赏

sangfor_闪电回_小六 发表于 2018-9-29 11:59
  
实用分享,:666:
907780 发表于 2018-10-8 13:19
  
非常实用
907780 发表于 2018-10-8 13:21
  
uuid。。。。。。。。。。。。。
plan_xp 发表于 2018-10-8 13:33
  
正好用上,谢了!
studying 发表于 2018-10-8 19:02
  
enenenne     学习
zoou 发表于 2018-10-9 11:16
  
看了两遍终于看懂了。原来是这个意思。
已完成 发表于 2018-10-9 17:43
  
直接没看明白
暗夜星空 发表于 2018-10-9 18:32
  
非常实用:好棒:
云程发轫 发表于 2018-10-10 14:08
  
非常有用,果断收藏了,
发表新帖
热门标签
全部标签>
每日一问
技术盲盒
技术笔记
每周精选
干货满满
技术咨询
信服课堂视频
秒懂零信任
自助服务平台操作指引
新版本体验
标准化排查
产品连连看
安装部署配置
功能体验
GIF动图学习
玩转零信任
2023技术争霸赛专题
技术晨报
安全攻防
每日一记
深信服技术支持平台
天逸直播
华北区交付直播
社区帮助指南
畅聊IT
答题自测
专家问答
技术圆桌
在线直播
MVP
网络基础知识
升级
上网策略
测试报告
日志审计
问题分析处理
流量管理
运维工具
云计算知识
用户认证
原创分享
解决方案
sangfor周刊
VPN 对接
项目案例
SANGFOR资讯
专家分享
技术顾问
信服故事
SDP百科
功能咨询
终端接入
授权
设备维护
资源访问
地址转换
虚拟机
存储
迁移
加速技术
排障笔记本
产品预警公告
信服圈儿
S豆商城资讯
技术争霸赛
「智能机器人」
追光者计划
答题榜单公布
纪元平台
通用技术
卧龙计划
华北区拉练
以战代练
山东区技术晨报
文档捉虫活动
齐鲁TV

本版版主

12
185
6

发帖

粉丝

关注

本版达人

LoveTec...

本周分享达人

新手24116...

本周提问达人