Linux Multipath+iscsi实现多路径配置

一、Multipath介绍

1、Multipath简介

普通的电脑主机都是一个硬盘挂接到一个总线上,这里是一对一的关系。而到了有光纤组成的SAN环境,由于主机和存储通过了光纤交换机连接,这样的话,就构成了多对多的关系。也就是说,主机到存储可以有多条路径可以选择。主机到存储之间的IO由多条路径可以选择。

2、实现功能

  • 故障的切换和恢复

  • IO流量的负载均衡

  • 磁盘的虚拟化

二、实验环境

主机名IP操作系统已有磁盘安装服务
server1(客户端) 10.10.10.1(eth0)、172.25.254.1(eth1) rhel7.3 sda、sdb iscsi-initiator-utils(发现iscsi)、multipath
server2(服务器端) 10.10.10.2(eth0)、172.25.254.2(eth1) rhel7.3 sda、sdb targetcli.noarch(iscsi服务)

三、iscsi安装(服务器端)

1、安装iscsi

 

[root@server1 ~]# yum install targetcli

 

2、配置iscsi

复制代码
2.1. 进入targetcli中进行设置

[root@server1 ~]# targetcli

Warning: Could not load preferences file /root/.targetcli/prefs.bin.

targetcli shell version 2.1.fb46

Copyright 2011-2013 by Datera, Inc and others.

For help on commands, type 'help'.

/> cd backstores/fileio

2.2. 创建一个磁盘镜像文件disk01.img,名称为disk01

/backstores/fileio> create disk01 /var/lib/iscsi_disks/disk01.img 5G

Created fileio disk01 with size 5368709120

/backstores/fileio> cd /iscsi

2.3. 创建一个target

/iscsi> create iqn.2017-10.com.smartmap:storage.target00

Created target iqn.2017-10.com.smartmap:storage.target00.

Created TPG 1.

Global pref auto_add_default_portal=true

Created default portal listening on all IPs (0.0.0.0), port 3260.

/iscsi> cd iqn.2017-10.com.smartmap:storage.target00/tpg1/luns

2.4. 设置LUN

/iscsi/iqn.20...t00/tpg1/luns> create /backstores/fileio/disk01

Created LUN 0.

/iscsi/iqn.20...t00/tpg1/luns> cd ../acls

2.5. 设置ACL

/iscsi/iqn.20...t00/tpg1/acls> create iqn.2017-10.com.smartmap:server1

Created Node ACL for iqn.2017-10.com.smartmap:server1

Created mapped LUN 0.

2.6. 为认证建立UserID

/iscsi/iqn.20...t00/tpg1/acls> set auth userid=username

Unknown configuration group: auth

/iscsi/iqn.20...t00/tpg1/acls> cd iqn.2017-10.com.smartmap:server1

/iscsi/iqn.20...server1> set auth userid=username

Parameter userid is now 'username'.

/iscsi/iqn.20...server1> set auth password=password

Parameter password is now 'password'.

/iscsi/iqn.20...server1> exit

Global pref auto_save_on_exit=true

Last 10 configs saved in /etc/target/backup.

Configuration saved to /etc/target/saveconfig.json

2.7. 配置完成后查看其监听

[root@server1 ~]# ss -napt | grep 3260

LISTEN 0 256 *:3260 *:*

2.8. 开启target服务

[root@server1 ~]# systemctl enable target

Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.

[root@server1 ~]#

2.9. 在防火墙中设置iSCSI Target服务

[root@server1 ~]# firewall-cmd --add-service=iscsi-target --permanent

success

[root@server1 ~]# firewall-cmd --reload

success

复制代码

四、iscsi配置(客户端)

1、安装并加入认证

复制代码
[root@server1 ~]# yum install -y iscsi-initiator-utils
[root@server1 ~]# vim /etc/iscsi/initiatorname.iscsi         
InitiatorName=iqn.2019-03.com.example:server1

[root@server1 ~]# vi /etc/iscsi/iscsid.conf
node.session.auth.authmethod = CHAP
# To set a CHAP username and password for initiator
# authentication by the target(s), uncomment the following lines:
node.session.auth.username = username
node.session.auth.password = password
复制代码

2、发现服务器端iscsi

复制代码
[root@server1 ~]# iscsiadm -m discovery -t st -p 10.10.10.2
10.10.10.2:3260,1 iqn.2019-03.com.example:server2

[root@server1 ~]# iscsiadm -m discovery -t st -p 172.25.254.2
172.25.254.2:3260,1 iqn.2019-03.com.example:server2


查看iSCSI-Target服务连接状态
[root@server1 ~]# iscsiadm -m node -o show
复制代码

3、登陆

复制代码
[root@server1 ~]# iscsiadm -m node --login
[root@server1 ~]# iscsiadm -m node -T iqn.2019-03.com.example:server2 -p 10.10.10.2 -l Logging in to [iface: default, target: iqn.2019-03.com.example:server2, portal: 10.10.10.2,3260] (multiple) Login to [iface: default, target: iqn.2019-03.com.example:server2, portal: 10.10.10.2,3260] successful. [root@server1 ~]# iscsiadm -m node -T iqn.2019-03.com.example:server2 -p 172.25.254.2 -l Logging in to [iface: default, target: iqn.2019-03.com.example:server2, portal: 172.25.254.2,3260] (multiple) Login to [iface: default, target: iqn.2019-03.com.example:server2, portal: 172.25.254.2,3260] successful.

验证建立会话状态
[root@server1 ~]# iscsiadm -m session -o show
复制代码

4、查看磁盘 

复制代码
[root@server1 ~]# fdisk -l
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: 0x00007256

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     2715647     1049600   82  Linux swap / Solaris
/dev/sda3         2715648    41943039    19613696   83  Linux

Disk /dev/sdb: 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 /dev/sdc: 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 / 4194304 bytes

Disk /dev/sdd: 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 / 4194304 bytes
复制代码

五、multipath安装及配置(客户端)

1、安装multipath

复制代码
[root@server1 ~]# yum -y install device-mapper-multipath
[root@server1 ~]# mpathconf --enable                 ###生成配置文件/etc/multipath.conf

### 也可以通过下面命令生成配置文件
[root@server1 ~]# modprobe dm-multipath
[root@server1 ~]# modprobe dm-round-robin
[root@server1 ~]# lsmod | grep dm_multipath
dm_multipath           23065  1 dm_round_robin
dm_mod                114430  3 dm_multipath,dm_log,dm_mirror

[root@server1 ~]# rpm -ql device-mapper-multipath     ###查看生成文件
[root@server1 ~]# cp /usr/share/doc/device-mapper-multipath-0.4.9/multipath.conf /etc/
复制代码

2、查看wwid

[root@server1 ~]# cat /etc/multipath/wwids
3600508b4000156d700012000000b0000

3、配置multipath

[root@server1 ~]# systemctl start multipathd.service
[root@server1 ~]# vi /etc/multipath/bindings
disk01 3600508b4000156d700012000000b0000

3、启用 multipath 设备 


[root@server1 ~]# systemctl stop multipathd.service
[root@server1 ~]# multipath -F 
[root@server1 ~]# systemctl start multipathd.service

4、查看状态 

[root@server1 ~]# multipath -rr
[root@server1 ~]# multipath -ll 

五、相关配置汇总

复制代码

iscsiadm的命令

1.发现iscsi存储: iscsiadm -m discovery -t st -p ISCSI_IP

2.查看iscsi发现记录 iscsiadm -m node

3.删除iscsi发现记录 iscsiadm -m node -o delete -T LUN_NAME -p ISCSI_IP

4.登录iscsi存储 iscsiadm -m node -T LUN_NAME -p ISCSI_IP -l

5.登出iscsi存储 iscsiadm -m node -T LUN_NAME -p ISCSI_IP -u
复制代码

 

posted @   ApeNet  阅读(1057)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示