RH436 UNIT 4 MULTIPATHING

Introduction

Unit Goal

        Describe multipathing

        Configure dm-multipath

Unit Sections

        What is Multipathing?

        Configuring Multipathing

        Testing Multipathing

Hands-On Activities

        Configure Multipathing

        Testing Multipathing

Unit Test

        Configuring Multipathing

What is Multipathing?

        所謂多路徑是實現在服務器與磁盤陣列之間配置多條物理連接。多路徑的優點有二,其一是在一條路徑癱瘓時不會影響連通性,另外可以改善對存儲的讀寫性能。

        如下圖,服務器有兩個HBA,都是獨立連接到光纖交換機,每一條連接都連接着磁盤陣列上獨立的控制器上。

image

        Red Hat Enterprise Linux 6 支持使用dm-multipath,這種方式是使用kernel磁盤映射生成一個虛擬的磁盤設備。通過multipathd的進程和multipath命令進行管理。

        必要的binaries,daemons,and kernel modules可以再device-mapper-multipath 包中找到。

        安裝device-mapper-multipath軟件包,配置並啓動後,會創建/dev/mapper,多路徑的SYMLINK會被創建在其中,名稱可以爲mpatchN[pM],或者使用WWID,管理員也可以自定義多路徑設備的名稱。

Important

        多路徑只是提供接入的冗餘,防護連接出現斷開。如果存儲本身出現問題,即使配置多路徑還是無法訪問存儲。

        通過配置文件創建不同的路徑連接存儲,這些Path會被整合到不同的組中,當一個組爲fails狀態的時候會跳到另外一個組保證可以正常訪問存儲。

What is multipathing?

1. Multipathing can provide..    A,B

a. Redundancy in storage access

b. Increased performance

c. Storage redundancy

d. RAID

2. The package that provides multipathing capabilities is called..   C

a. dm-multipath

b. dm-multipathd

c. divice-mapper-multipath

d. multipathd

3. Devices nodes for multipathed storage are normally created under..   C

a. /dev/

b. /dev/multipath/

c. /dev/mapper/

d. /dev/dm-multipath

Configuring Multipathing

        配置多路徑之前先確保device-mapper-multipath package已安裝。

        配置兩個網卡作爲多路徑的訪問路徑。

eth1      Link encap:Ethernet  HWaddr 00:0C:29:B3:DE:A4 
          inet addr:172.16.1.4  Bcast:172.16.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:feb3:dea4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:28 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1756 (1.7 KiB)  TX bytes:1000 (1000.0 b)

eth2      Link encap:Ethernet  HWaddr 00:0C:29:B3:DE:AE 
          inet addr:172.16.2.4  Bcast:172.16.2.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:feb3:deae/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:13 errors:0 dropped:0 overruns:0 frame:0
          TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:780 (780.0 b)  TX bytes:1440 (1.4 KiB)

        安裝完device-mapper-multipath 軟件包之後開始配置multipath的配置文件,最簡單的方式是使用mpathconf工具進行配置。

        如果已經/etc/multipath.conf已經存在,那麼可以直接使用mpathconf進行配置,如果不存在,可以再/usr/share/doc/device-mapper-multipath-*下面找到multipath.conf的模板。也可以通過mpathconf命令創建默認模板。

        創建默認配置,啓動和激活multipathd進程,可以使用以下命令。

mpathconf --enable --with_multipathd y --with_chkconfig y

--enable
       Removes any line that blacklists all device nodes from the /etc/multipath.conf blacklist section.

--with_multipathd { y | n }
       If set to y, this runs service multipathd start to start the multipathd daemon on --enable, service mul-
       tipathd stop to start the multipathd daemon on --disable, and service multipathd reload  to  reconfigure
       multipathd on --user_frindly_names and --find_multipaths.  This option is set to n by default.

        添加此參數會使用service multipathd start啓動multipathd服務,前提是參數爲y ,如果爲n則爲停止服務,默認爲n。

--with_chkconfig { y | n }
       If  set to y, this runs chkconfig multipathd on to set multipathd to start automatically on --enable and
       chkconfig multipathd off to stop multipathd for starting automatically on --disable.  This option is set
       to y by default.

        如果爲y,則執行chkconfig multipathd on設置開機啓動,如果爲n則爲off關閉開機啓動,默認爲y。

Note

        關於—user_friendly_names 參數,如果設置爲y,則使用友好名稱作爲多路徑磁盤的名稱,如果設置爲n,則爲使用WWID作爲SYMLINK的名稱。使用mpathconf –user_friendly_names y|n 進行設置,通過此命令會直接修改配置文件。

[root@node1 nodes]# mpathconf --user_friendly_names n

## Use user friendly names, instead of using WWIDs as names.
defaults {
        user_friendly_names no
}
##

Disk /dev/mapper/1IET\x20\x20\x20\x20\x2000010001: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00001618

                                        Device Boot      Start         End      Blocks   Id  System

如果設置爲y ,重啓後結果爲

Disk /dev/mapper/mpatha: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00001618

             Device Boot      Start         End      Blocks   Id  System

The multipath.conf Configuration File

        在multipath.conf配置文件中包含以下5部分內容

blacklist{}

        此列表中的devices將被排除在多路徑的拓撲之外。for example,在配置文件中添加以下行

        blacklist {
                device{
                wwid    1IET_00010001
                }
        }

        重啓多路徑進程,重新登錄target,發現物mpatha設備已消失。

blacklist_exceptions{}

        此列表爲允許的device加入多路徑組,及時它同時存在於blacklist之中。

defaults{}

        此列表內存儲針對所有多路徑的默認設置,除非他有設置相同屬性在devices{},或者multipaths{}之中。

devices{}

        此列表內存儲關於vendor,product的基本信息,此列表會覆蓋defaults{}列表裏面的內容,但是不會覆蓋multipaths{}裏面的內容。(可通過正則表達式匹配sysfs中的內容)

multipaths{}

        此列表存儲多路徑的基本設置,它的內容會覆蓋defaults{}和devices{}中的內容。多路徑會確認WWIDs上的信息。(獲取可使用getuid_callout函數)

以下會對各列表做解釋和舉例

Blacklisting

        將設備列入多路徑的黑名單可以使用multipath.conf配置文件的blacklist{}部分。你可以再blacklist中使用通配符匹配多數設備,然後使用blacklist_exceptions{}排除要加入多路徑的設備。在Blacklist中可以使用device node或者WWID進行匹配。例如:

blacklist {
        devnode "sdb"
}

        設置之後,重啓多路徑服務,剛纔的mapper就不存在了。

[root@node1 ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a996c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        1332    10485760   83  Linux
/dev/sda3            1332        1462     1048576   82  Linux swap / Solaris

Disk /dev/sdb: 1073 MB, 1073741824 bytes
34 heads, 61 sectors/track, 1011 cylinders
Units = cylinders of 2074 * 512 = 1061888 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00001618

   Device Boot      Start         End      Blocks   Id  System
[root@node1 ~]#

Defaults

        在multipath.conf配置文件中的defaults{}進行設置屬性被視爲多路徑的默認屬性。如果想查詢defaults可以配置哪些屬性可以通過/usr/share/doc/device-mapper-multipath-*/multipath.conf.defaults找到。

常用的設置如下:

path_selector(路徑選擇器):此算法決定在group中哪一個path作爲下一個I/O。默認情況下使用“round-robin 0” (循環模式),將I/O分佈在group中的每個paths之中。rr_min_io_rq設置爲一定量的I/O,默認爲1000,在I/O達到1000之後會切換到下一個path。queue-length 0爲判斷當前請求數最少的path作爲下一個請求的目標。service-time 0爲通過算法計算服務響應請求時間最短的路徑併發送。

path_grouping_policy(路徑組策略): 指定默認分組策略適用於沒有指定的多路徑,這些值可能包括:

        failover(故障轉移):每個路徑在獨立的組中。

        multibus(多總線):所有路徑在一個組中,這種方式可以支持active-active的連接模式。

path_checker(路徑檢查):用來指定判斷路徑是否存活的方式。一般設置爲directio或者readsector模式,如果有特殊設備需要使用指定的checker,則在devices{}中添加覆蓋defaults{}中的設置。

        directio(直連): 通過路徑對目標設備的第一塊扇區進行I/O測試

        readsector(讀取扇區):通過路徑讀取目標的第一塊扇區

user_friendly_names(用戶友好名稱):這項設置決定多路徑節點是否使用user_friendly_names,如果爲yes,則就會設置別名爲mpathN,否則會使用設備的WWID作爲SYMLINKS。

Important:mpathconf 將改變multipath.conf中的defaults設置,但是不會對multipathd進程做出改變。

The devices{} Section

        在devices{}列表中可以對一些特殊設備做設置從而覆蓋掉defaults{}中相同的屬性。在devices{}列表中可以使用devices{}作爲子列表對特殊設備進行定義。常見的設備的一些屬性在多路徑進程中已經內置存在,如果沒有也可以添加一個device{}進行配置。範例:

devices {
        device {
                vendor "MegaHyperSuperStorage"
                product "BAS"
                revision "513/B"
                features "1 queue_if_no_path"
                path_grouping_policy multibus
                path_checker tur
        }
}

        其中features行表示如果沒有path可用,仍然對I/O請求進行接收和加入隊列。

The multipaths{} section

        在multipaths{}可以定義特殊的多路徑設備。可以使用這個對特殊的多路徑定製path_grouping策略。通常使用Multipaths定義多路徑的alias,爲了區分不同的多路徑設備。下列範例匹配WWI爲1234567890abcdef的設備alias爲clusterstorage,path_selector爲queue-length 0 (路徑選擇器,發送下一個I/O請求到隊列最少的路徑中)。

multipaths {
        multipath {
                wwid "1234567890abcdef"
                alias "clusterstorage"
                path_selector "queue-length 0"
        }
}

Configure Multipathing

Lab Overview: 此實驗你將配置多路徑,在node1上配置兩個路徑對target

Success Criteria:完成目標,成功在node1上激活iSCSI目標,目標有兩條iscsi路徑

Before you begin…

Make sure that the iSCSI target define on node4 is still running

1. 重新安裝node1虛擬機,使用lab-build-cluster -1命令(課本實驗環境使用KVM實現,按照要求部署實驗環境科免去此步驟)

2. 在node4上添加acl,使得node1和node3的網卡都可以成功登陸,設置之後需要重啓tgtd服務,如果還有initiator登陸,則使用force-restart參數強制重啓。

ACL information:
    ALL

        這裏設置ACL爲ALL,所有用戶都可登陸。

3. 設置node1的iSCSI initiator name爲 iqn.2012-04.com.example:node1

vim /etc/iscsi/initiatorname.iscsi   添加 InitiatorName=iqn.2012-04.com.example:node1

重啓iscsi服務後在node4上使用tgt-admin -s查看  (可能有緩存造成無法更新狀態,重啓node1之後生效)

System information:
    Driver: iscsi
    State: ready
I_T nexus information:
    I_T nexus: 7
        Initiator: iqn.2012-04.com.example:node1
        Connection: 0
            IP Address: 172.16.1.1
    I_T nexus: 8
        Initiator: iqn.2012-04.com.example:node1
        Connection: 0
            IP Address: 172.16.2.1

4.  在node1上設置default iscsi tmeouts爲2秒。

[root@node1 ~]# vim /etc/iscsi/iscsid.conf

node.session.timeo.replacement_timeout = 2

# To specify the time to wait for login to complete, edit the line.
# The value is in seconds and the default is 15 seconds.
node.conn[0].timeo.login_timeout = 2

# To specify the time to wait for logout to complete, edit the line.
# The value is in seconds and the default is 15 seconds.
node.conn[0].timeo.logout_timeout = 2

# Time interval to wait for on connection before sending a ping.
node.conn[0].timeo.noop_out_interval = 2

# To specify the time to wait for a Nop-out response before failing
# the connection, edit this line. Failing the connection will
# cause IO to be failed back to the SCSI layer. If using dm-multipath
# this will cause the IO to be failed to the multipath layer.
node.conn[0].timeo.noop_out_timeout = 2

# To specify the time to wait for abort response before
# failing the operation and trying a logical unit reset edit the line.
# The value is in seconds and the default is 15 seconds.
node.session.err_timeo.abort_timeout = 2

# To specify the time to wait for a logical unit response
# before failing the operation and trying session re-establishment
# edit the line.
# The value is in seconds and the default is 30 seconds.
node.session.err_timeo.lu_reset_timeout = 2

# To specify the time to wait for a target response
# before failing the operation and trying session re-establishment
# edit the line.
# The value is in seconds and the default is 30 seconds.
node.session.err_timeo.tgt_reset_timeout = 2

如果已經Login,則需要在節點信息中修改

cd /var/lib/iscsi/nodes/iqn.2013-11.com.example.node4\:example/

5. 在node1上通過兩塊網卡discovery並log in 到node4的target中。

Disk /dev/sdd: 1073 MB, 1073741824 bytes
34 heads, 61 sectors/track, 1011 cylinders
Units = cylinders of 2074 * 512 = 1061888 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sde: 1073 MB, 1073741824 bytes
34 heads, 61 sectors/track, 1011 cylinders
Units = cylinders of 2074 * 512 = 1061888 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

6. 確保node1上已經安裝device-mapper-multipath 軟件包。

[root@node1 172.16.1.4,3260,1]# rpm -qa|grep device-mapper-multipath
device-mapper-multipath-libs-0.4.9-56.el6.x86_64
device-mapper-multipath-0.4.9-56.el6.x86_64
[root@node1 172.16.1.4,3260,1]#

7. 創建Multipathd默認配置文檔,不使用user friendly names 並不啓動進程。

mpathconf --enable --with_multipathd n --user_friendly_names n

[root@node1 172.16.1.4,3260,1]# service multipathd status
multipathd is stopped

## Use user friendly names, instead of using WWIDs as names.
defaults {
        user_friendly_names no
}
##

8. 添加以下行到defaults{}之中,確保多路徑使用WWID,不會造成混亂。

## Use user friendly names, instead of using WWIDs as names.
defaults {
        user_friendly_names no
        getuid_callout "lib/udev/scsi_id --replace-whitespace --whitelisted --device=/dev/%n"
}
##

9. 啓動multipathd進程

[root@node1 ~]# service multipathd start
Starting multipathd daemon: [  OK  ]

發現多了一塊設備

Disk /dev/mapper/1IET_00010001: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Testing Multipathing

Lab Overview:本次實驗需要創建一個分區在多路徑設備上,創建一個文件系統並測試多路徑設置。

Success Criteria:成功指標爲成功掛載到文件系統上,並保證每一條path可以訪問。

Lab Outline : In this exercise you will create a partition and a file system on multipathed storage . mount it , and test multipathing.

Before you begin…

        確保node4上面的target訪問正常,並且在之前的實驗中配置好了多路徑在node1上。

1. 創建128Mib 的分區在多路徑設備上

[root@node1 ~]# fdisk -cu /dev/mapper/1IET_00010001
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xa4a7cfad.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-2097151, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +128M

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 22: Invalid argument.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

[root@node1 ~]# fdisk -l /dev/mapper/1IET_00010001

Disk /dev/mapper/1IET_00010001: 1073 MB, 1073741824 bytes
114 heads, 33 sectors/track, 557 cylinders
Units = cylinders of 3762 * 512 = 1926144 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa4a7cfad

                     Device Boot      Start         End      Blocks   Id  System
/dev/mapper/1IET_00010001p1               1          71      131072   83  Linux

2. 確保系統已經識別到新的分區

[root@node1 ~]# partprobe; multipath –r

[root@node1 ~]# ls -rlt /dev/mapper/1IET_00010001p1
lrwxrwxrwx. 1 root root 7 Nov  6 23:05 /dev/mapper/1IET_00010001p1 -> ../dm-0

3. 創建ext4文件系統並將分區掛載到/mnt下。

[root@node1 ~]# mkfs.ext4 /dev/mapper/1IET_00010001p1

[root@node1 ~]# mount /dev/mapper/1IET_00010001p1 /mnt

4. 通過multipath –ll 命令查看多路徑狀態

[root@node1 ~]# multipath -ll
1IET_00010001 dm-1 IET,VIRTUAL-DISK
size=1.0G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=1 status=active
| `- 8:0:0:1 sdd 8:48 active ready running
`-+- policy='round-robin 0' prio=1 status=enabled
  `- 7:0:0:1 sde 8:64 active ready running

5. 關閉正在active的網卡,再查看狀態。

[root@node1 mnt]# multipath -ll
1IET_00010001 dm-1 IET,VIRTUAL-DISK
size=1.0G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=1 status=active
| `- 8:0:0:1 sdd 8:48 active ready  running
`-+- policy='round-robin 0' prio=0 status=enabled
  `- 7:0:0:1 sde 8:64 failed faulty running  

[root@node1 mnt]# touch test
[root@node1 mnt]# ls -rlt
total 13
drwx------. 2 root root 12288 Nov  6 23:07 lost+found
-rw-r--r--. 1 root root     0 Nov  6 23:19 test
[root@node1 mnt]#

6. 重新啓動網卡,看是否恢復正常。

[root@node1 mnt]# multipath -ll
1IET_00010001 dm-1 IET,VIRTUAL-DISK
size=1.0G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=1 status=active
| `- 8:0:0:1 sdd 8:48 active ready running
`-+- policy='round-robin 0' prio=1 status=enabled
  `- 7:0:0:1 sde 8:64 active ready running

Configuring Multipathing

Lab Overview: 配置多路徑設備,自定義設備別名。

Success Criteria:成功條件爲爲多路徑設備創建自定義名稱。

添加配置到多路徑配置文件

multipaths {
        multipath {
        wwid "1IET     00010001"
        alias "clusterstorage"
        }
}

重啓服務後可以看到

Disk /dev/mapper/clusterstorage: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa4a7cfad

                     Device Boot      Start         End      Blocks   Id  System

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章