配置iscsi多路径实现磁盘挂载高可用
配置iscsi多路径实现磁盘挂载高可用
1.1 准备实验环境
如果存储服务器到交换机只有一条线路的时候,那么一条线路出现故障,整个就没法使用了,所以多线路可以解决这个问题,避免单点故障
通过VMware模拟多路径,使用下面的拓扑:
将k92配置成ip san,将k92上的sdb1分区,通过ip san 共享出去。
服务器端: target k92
客户端: initiator k93
2、固化两台电脑的IP
1.3 搭建target服务器
[root@k92 ~]# yum -y install targetcli
[root@k92 yum.repos.d]# targetcli
/> /backstores/block create kezi /dev/sdb
/> /iscsi create iqn.2019-09.cn.k92:server
/> /iscsi/iqn.2019-09.cn.k92:server/tpg1/acls/ create iqn.2019-09.cn.k92:k93
/> /iscsi/iqn.2019-09.cn.k92:server/tpg1/luns/ create /backstores/block/kezi
添加双IP
/> /iscsi/iqn.2019-09.cn.k92:server/tpg1/portals/ delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/> /iscsi/iqn.2019-09.cn.k92:server/tpg1/portals/ create 192.168.1.92 3260
Using default IP port 3260
Created network portal 192.168.1.92:3260.
/> /iscsi/iqn.2019-09.cn.k92:server/tpg1/portals/ create 192.168.2.2 3260
Using default IP port 3260
Created network portal 192.168.2.2:3260.
保存
/> saveconfig
/> exit
启动iscsi
[root@k92 ~]# systemctl restart target && systemctl enable target
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
[root@k92 ~]# netstat -antup | grep 3260
tcp 0 0 192.168.1.92:3260 0.0.0.0:* LISTEN -
tcp 0 0 192.168.2.2:3260 0.0.0.0:* LISTEN
1.4 搭建target客户端并挂载存储
[root@k93 yum.repos.d]# yum install -y iscsi-initiator-utils
[root@k93 yum.repos.d]# systemctl start iscsi
[root@k93 yum.repos.d]# systemctl start iscsi
[root@k93 yum.repos.d]# systemctl enable iscsi
[root@k93 yum.repos.d]# systemctl enable iscsid
[root@k93 yum.repos.d]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2019-09.cn.k92:k93
重启客户端
[root@k93 yum.repos.d]# systemctl restart iscsid
发现ISCSI
[root@k93 yum.repos.d]# iscsiadm -m discovery -t st -p 192.168.2.2
192.168.2.2:3260,1 iqn.2019-09.cn.k92:server
192.168.1.92:3260,1 iqn.2019-09.cn.k92:server
连接ISCSI设备
[root@k93 yum.repos.d]# iscsiadm -m node --login
Logging in to [iface: default, target: iqn.2019-09.cn.k92:server, portal: 192.168.2.2,3260] (multiple)
Logging in to [iface: default, target: iqn.2019-09.cn.k92:server, portal: 192.168.1.92,3260] (multiple)
Login to [iface: default, target: iqn.2019-09.cn.k92:server, portal: 192.168.2.2,3260] successful.
Login to [iface: default, target: iqn.2019-09.cn.k92:server, portal: 192.168.1.92,3260] successful.
查看设备
[root@k93 yum.repos.d]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sdb /dev/sdc
[root@k93 yum.repos.d]# blkid /dev/sdc /dev/sdb
/dev/sdc: UUID="b54cd2c8-c4c9-4fa0-8703-97472e0da238" TYPE="xfs"
/dev/sdb: UUID="b54cd2c8-c4c9-4fa0-8703-97472e0da238" TYPE="xfs"
格式化挂载(已格式化忽略)
[root@k93 yum.repos.d]# mkfs.xfs /dev/sdb -f
测试挂载写数据
[root@k93 yum.repos.d]# mount /dev/sdb /opt
[root@k93 yum.repos.d]# echo aabbcc >/opt/a.txt
[root@k93 yum.repos.d]# mkdir /test
跳过UUID挂载
[root@k93 yum.repos.d]# mount -t xfs -o nouuid /dev/sdc /test
服务端查看链接状态
[root@k93 yum.repos.d]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 28G 3.9G 24G 14% /
devtmpfs 477M 0 477M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.8M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 497M 137M 361M 28% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb 1014M 33M 982M 4% /opt
/dev/sdc 1014M 33M 982M 4% /test
[root@k93 yum.repos.d]# netstat -antup | grep 3260
tcp 0 0 192.168.2.3:47562 192.168.2.2:3260 ESTABLISHED 2218/iscsid
tcp 0 0 192.168.1.93:53688 192.168.1.92:3260 ESTABLISHED 2218/iscsid
查看连接结构:
[root@k93 yum.repos.d]# yum install tree -y
[root@k93 yum.repos.d]# tree /var/lib/iscsi/
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
│ └── iqn.2019-09.cn.k92:server
│ ├── 192.168.1.92,3260,1
│ │ └── default
│ └── 192.168.2.2,3260,1
│ └── default
├── send_targets
│ ├── 192.168.2.2,3260
│ │ ├── iqn.2019-09.cn.k92:server,192.168.1.92,3260,1,default -> /var/lib/iscsi/nodes/iqn.2019-09.cn.k92:server/192.168.1.92,3260,1
│ │ ├── iqn.2019-09.cn.k92:server,192.168.2.2,3260,1,default -> /var/lib/iscsi/nodes/iqn.2019-09.cn.k92:server/192.168.2.2,3260,1
│ │ └── st_config
│ └── 192.168.2.3,3260
│ └── st_config
├── slp
└── static
13 directories, 4 files