Linux 系统配置多路径

1、Multipath简介

由于光纤组成的SAN环境中主机和存储通过了光纤交换机连接,这样,就构成了多对多的关系。也就是说,主机到存储可以有多条路径可以选择。当我们通过存储为主机分配了一块存储空间后,通过我们主机查看发现存在有多块一模一样的磁盘盘符,这时候就需要在系统上配置多路径,实现故障的切换和恢复,IO流量的负载均衡,磁盘的虚拟化等功能。

2、实验环境

主机名IP操作系统
iscsi-server192.168.136.161/192.168.182.161rhel 7.6
client192.168.136.176/192.168.182.176rhel 7.6

由于我们这里没有存储设备,所以选择使用ISCSI块存储服务来模拟存储设备,通过在iscsi-server主机上绑定两个ip地址,来模拟存储设备到主机client的双链路。
关闭防火墙和selinux

systemctl stop firewalld
setenforce 0

查看iscsi-server上空闲的磁盘信息

[root@ansible-server ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

3、实验步骤

3.1、iscsi-server 主机配置

3.1.1、安装ISCSI块存储服务
[root@iscsi-server ~]# yum install -y targetcli
[root@iscsi-server ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb49
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/>/backstores/block create dream:storage1 /dev/sdb
Created block storage object dream:storage1 using /dev/sdb.
/> /iscsi create iqn.2020-10.com.example:iscsi-server   
Created target iqn.2020-10.com.example:iscsi-server.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/> /iscsi/iqn.2020-10.com.example:iscsi-server/tpg1/acls create iqn.2020-10.com.example:iscsi-server
Created Node ACL for iqn.2020-10.com.example:iscsi-server
/> /iscsi/iqn.2020-10.com.example:iscsi-server/tpg1/luns create /backstores/block/dream:storage1      
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2020-10.com.example:iscsi-server
/> exit
Global pref auto_save_on_exit=true
Configuration saved to /etc/target/saveconfig.json
3.1.2、iscsi-server 启动服务
[root@iscsi-server ~]# systemctl start target
[root@iscsi-server ~]# systemctl status target
● target.service - Restore LIO kernel target configuration
   Loaded: loaded (/usr/lib/systemd/system/target.service; disabled; vendor preset: disabled)
   Active: active (exited) since Mon 2020-10-19 14:50:36 CST; 3min 11s ago
  Process: 13127 ExecStart=/usr/bin/targetctl restore (code=exited, status=0/SUCCESS)
 Main PID: 13127 (code=exited, status=0/SUCCESS)
    Tasks: 0
   Memory: 0B
   CGroup: /system.slice/target.service

Oct 19 14:50:36 ansible-server systemd[1]: Starting Restore LIO kernel target configuration...
Oct 19 14:50:36 ansible-server systemd[1]: Started Restore LIO kernel target configuration.

3.2、clent 主机配置

3.2.1、安装 iscsi-initiator-utils
[root@client ~]# yum install -y iscsi-initiator-utils
3.2.2、加入iscsi认证
[root@client ~]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2020-10.com.example:iscsi-server
3.2.3、 发现服务端ISCSI设备
[root@client ~]# iscsiadm -m discovery -t st -p 192.168.136.161    
192.168.136.161:3260,1 iqn.2020-10.com.example:iscsi-server
[root@client ~]# iscsiadm -m discovery -t st -p 192.168.182.161
192.168.182.161:3260,1 iqn.2020-10.com.example:iscsi-server
3.2.4、登陆设备
[root@client ~]# iscsiadm -m node -T iqn.2020-10.com.example:iscsi-server -p 192.168.136.161 -l
Logging in to [iface: default, target: iqn.2020-10.com.example:iscsi-server, portal: 192.168.136.161,3260] (multiple)
Login to [iface: default, target: iqn.2020-10.com.example:iscsi-server, portal: 192.168.136.161,3260] successful.
[root@client ~]# iscsiadm -m node -T iqn.2020-10.com.example:iscsi-server -p 192.168.182.161 -l  
Logging in to [iface: default, target: iqn.2020-10.com.example:iscsi-server, portal: 192.168.182.161,3260] (multiple)
Login to [iface: default, target: iqn.2020-10.com.example:iscsi-server, portal: 192.168.182.161,3260] successful.
3.2.5、查看client主机磁盘信息
[root@client ~]# fdisk -l

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b228d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   209715199   104856576   8e  Linux LVM

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000e07df

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     4196351     2097152   83  Linux
/dev/sda2         4196352    41943039    18873344   8e  Linux LVM

Disk /dev/mapper/rhel-root: 53.7 GB, 53682896896 bytes, 104849408 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/rhel-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/rhel-var: 70.9 GB, 70862766080 bytes, 138403840 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes


Disk /dev/sdd: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes

可以发现多了sdc、和sdd二块磁盘,而且信息一样,如果不配置多路径,将会被系统识别成二块磁盘,但是实际系统读写的为一块,所以需要配置多路径,实现灾备功能。

3.3、多路径软件安装与配置

下面的操作在client主机上执行

3.3.1、安装多路径管理软件
[root@client ~]# yum -y install device-mapper-multipath
[root@client ~]# modprobe dm-multipath
[root@client ~]# modprobe dm-round-robin
[root@client ~]# lsmod | grep dm_multipath
dm_multipath           27427  1 dm_round_robin
dm_mod                123303  14 dm_round_robin,dm_multipath,dm_log,dm_mirror
[root@client ~]# mpathconf --enable			#生成配置文件
3.3.2 、查看wwid
[root@client ~]# /usr/lib/udev/scsi_id --whitelisted --device=/dev/sdc
36001405c283aa2f3fa54edaa6d112ea6
[root@client ~]# /usr/lib/udev/scsi_id --whitelisted --device=/dev/sdd
36001405c283aa2f3fa54edaa6d112ea6
3.2.3 、配置multipath
[root@client ~]# vim /etc/multipath.conf
defaults {
        user_friendly_names yes
        find_multipaths yes
}
multipaths {
    multipath {
        wwid    36001405c283aa2f3fa54edaa6d112ea6
        alias   msda
  }

查看新生成的设备“msda”

[root@client ~]# systemctl start multipathd
[root@client ~]# ls /dev/mapper/
control  msda  rhel-root  rhel-swap  rhel-var
3.2.4、挂载和格式化
[root@client ~]# mkfs.xfs /dev/mapper/msda 
meta-data=/dev/mapper/msda       isize=512    agcount=4, agsize=655360 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2621440, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@client ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   50G  983M   50G   2% /
devtmpfs               2.0G     0  2.0G   0% /dev
tmpfs                  2.0G     0  2.0G   0% /dev/shm
tmpfs                  2.0G  8.7M  2.0G   1% /run
tmpfs                  2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/mapper/rhel-var    66G  108M   66G   1% /var
/dev/sda1              2.0G  125M  1.9G   7% /boot
tmpfs                  394M     0  394M   0% /run/user/0
/dev/sr0               3.8G  3.8G     0 100% /mnt
[root@client ~]# mkdir /data
[root@client ~]# mount /dev/mapper/msda /data
[root@client ~]# df -h                       
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   50G  983M   50G   2% /
devtmpfs               2.0G     0  2.0G   0% /dev
tmpfs                  2.0G     0  2.0G   0% /dev/shm
tmpfs                  2.0G  8.7M  2.0G   1% /run
tmpfs                  2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/mapper/rhel-var    66G  108M   66G   1% /var
/dev/sda1              2.0G  125M  1.9G   7% /boot
tmpfs                  394M     0  394M   0% /run/user/0
/dev/sr0               3.8G  3.8G     0 100% /mnt
/dev/mapper/msda        10G   33M   10G   1% /data
3.2.5、查看状态
[root@client ~]# multipath -ll
Oct 19 15:23:16 | /etc/multipath.conf line 100, invalid keyword: blacklist
msda (36001405c283aa2f3fa54edaa6d112ea6) dm-3 LIO-ORG ,dream:storage1  
size=10G features='0' hwhandler='0' wp=rw
|-+- policy='service-time 0' prio=1 status=active
| `- 33:0:0:0 sdc 8:32 active ready running
`-+- policy='service-time 0' prio=1 status=enabled
  `- 34:0:0:0 sdd 8:48 active ready running
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值