說明: 對於有兩個或多個控制器的iscsi存儲設備,或采用openfiler有兩塊網卡提供服務器的系統。需要配置多路徑功能提高可用性。
本文采用openfiler來實現iscsi設備的安裝與測試。
本文NAS采用openfiler 2.99.1 X64做為實驗環境,為近期的一個備份環境部署做准備。
1. 並安裝iSCSI啟動器軟件包
rpm -ivh iscsi-initiator-utils-6.2.0.871-0.10.el5.i386.rpm
chkconfig --level 2345 iscsi on
chkconfig --level 2345 iscsid on
service iscsi start
service iscsid start
2. 多路徑軟件安裝准備
# rpm -qa |grep mapper
device-mapper-event-1.02.55-2.el5
device-mapper-1.02.55-2.el5
device-mapper-multipath-0.4.7-42.el5
#
設置成開機自啟動multipathd
# chkconfig --level 2345 multipathd on
來檢查安裝是否正常
# lsmod |grep dm_multipath
dm_multipath 25421 0
scsi_dh 12097 1 dm_multipath
dm_mod 63097 11 dm_multipath,dm_raid45,dm_snapshot,dm_zero,dm_mirror,dm_log
3. 發現存儲設備
# iscsiadm -m discovery -t st -p 192.168.100.238
192.168.100.238:3260,1 iqn.2006-01.com.openfiler:tsn.f9d59aaffe9c
192.168.100.239:3260,1 iqn.2006-01.com.openfiler:tsn.f9d59aaffe9c
4. 連接兩個節點,通過兩個IP分別進行連接
(1) 連接登陸第一個IP
# iscsiadm -m node -T iqn.2006-01.com.openfiler:tsn.f9d59aaffe9c -p 192.168.100.238 -l
Logging in to [iface: default, target: iqn.2006-01.com.openfiler:tsn.f9d59aaffe9c, portal: 192.168.100.238,3260]
Login to [iface: default, target: iqn.2006-01.com.openfiler:tsn.f9d59aaffe9c, portal: 192.168.100.238,3260] successful.
(2) 連接登錄第二個IP
# iscsiadm -m node -T iqn.2006-01.com.openfiler:tsn.f9d59aaffe9c -p 192.168.100.239 -l
Logging in to [iface: default, target: iqn.2006-01.com.openfiler:tsn.f9d59aaffe9c, portal: 192.168.100.239,3260]
Login to [iface: default, target: iqn.2006-01.com.openfiler:tsn.f9d59aaffe9c, portal: 192.168.100.239,3260] successful.
5. 查看連接狀態
(1) 查看連接狀態1
# iscsiadm -m session
tcp: [1] 192.168.14.180:3260,1 iqn.2006-01.com.openfiler:tsn.355d1613342d
tcp: [2] 192.168.14.181:3260,1 iqn.2006-01.com.openfiler:tsn.355d1613342d
(2) 查看iSCSI連接設備
# ls -l /dev/disk/by-path/
lrwxrwxrwx 1 root root 9 Jan 7 10:52 ip-192.168.100.238:3260-iscsi-iqn.2006-01.com.openfiler:tsn.f9d59aaffe9c-lun-0 -> ../../sda
lrwxrwxrwx 1 root root 9 Jan 7 10:54 ip-192.168.100.239:3260-iscsi-iqn.2006-01.com.openfiler:tsn.f9d59aaffe9c-lun-0 -> ../../sdb
lrwxrwxrwx 1 root root 9 Jan 7 10:28 pci-0000:00:07.1-ide-0:0 -> ../../hda
lrwxrwxrwx 1 root root 10 Jan 7 10:28 pci-0000:00:07.1-ide-0:0-part1 -> ../../hda1
lrwxrwxrwx 1 root root 10 Jan 7 10:28 pci-0000:00:07.1-ide-0:0-part2 -> ../../hda2
lrwxrwxrwx 1 root root 9 Jan 7 10:28 pci-0000:00:07.1-ide-1:0 -> ../../hdc
(3) 查看詳細連接狀態
# iscsiadm -m session -P 3
iSCSI Transport Class version 2.0-871
version 2.0-872
Target: iqn.2006-01.com.openfiler:tsn.f9d59aaffe9c
Current Portal: 192.168.100.238:3260,1
Persistent Portal: 192.168.100.238:3260,1
**********
Interface:
**********
Iface Name: default
Iface Transport: tcp
Iface Initiatorname: iqn.1994-05.com.redhat:e2b7fdf48ccd
Iface IPaddress: 192.168.100.175
Iface HWaddress: <empty>
Iface Netdev: <empty>
SID: 1
iSCSI Connection State: LOGGED IN
iSCSI Session State: LOGGED_IN
Internal iscsid Session State: NO CHANGE
************************
Negotiated iSCSI params:
************************
HeaderDigest: None
DataDigest: None
MaxRecvDataSegmentLength: 262144
MaxXmitDataSegmentLength: 131072
FirstBurstLength: 262144
MaxBurstLength: 262144
ImmediateData: No
InitialR2T: Yes
MaxOutstandingR2T: 1
************************
Attached SCSI devices:
************************
Host Number: 0 State: running
scsi0 Channel 00 Id 0 Lun: 0
Attached scsi disk sda State: running
Current Portal: 192.168.100.239:3260,1
Persistent Portal: 192.168.100.239:3260,1
**********
Interface:
**********
Iface Name: default
Iface Transport: tcp
Iface Initiatorname: iqn.1994-05.com.redhat:e2b7fdf48ccd
Iface IPaddress: 192.168.100.175
Iface HWaddress: <empty>
Iface Netdev: <empty>
SID: 2
iSCSI Connection State: LOGGED IN
iSCSI Session State: LOGGED_IN
Internal iscsid Session State: NO CHANGE
************************
Negotiated iSCSI params:
************************
HeaderDigest: None
DataDigest: None
MaxRecvDataSegmentLength: 262144
MaxXmitDataSegmentLength: 131072
FirstBurstLength: 262144
MaxBurstLength: 262144
ImmediateData: No
InitialR2T: Yes
MaxOutstandingR2T: 1
************************
Attached SCSI devices:
************************
Host Number: 1 State: running
scsi1 Channel 00 Id 0 Lun: 0
Attached scsi disk sdb State: running
兩個設備sda,sdb分別由兩個IP進行提供服務,也可查看狀態都是LOGGED IN狀態。
6. 創建multipath配置文件
(1) 生成multipath配置文件
multipath默認配置文件/etc/multipath.conf。
如果/etc/multipath.conf文件不存在,可以使用以下命令創建multipath.conf文件:
mpathconf --enable
(2) 生成磁盤設備的WWID號
說明: 通常支持多路徑的情況下會出現雙份磁盤設備,依次執行以下命令。
/sbin/scsi_id -g -u -s /block/sda
/sbin/scsi_id -g -u -s /block/sdb
# /sbin/scsi_id -g -u -s /block/sda
14f504e46494c4552514a796e67642d786a4c642d42346271
# /sbin/scsi_id -g -u -s /block/sdb
14f504e46494c4552514a796e67642d786a4c642d42346271
# iscsiadm -m session
tcp: [1] 192.168.100.238:3260,1 iqn.2006-01.com.openfiler:tsn.f9d59aaffe9c
tcp: [2] 192.168.100.239:3260,1 iqn.2006-01.com.openfiler:tsn.f9d59aaffe9c
 
(3) 創建配置文件
# mv /etc/multipath.conf /etc/multipath.conf.bak
# grep -v '^#' /etc/multipath.conf.bak > /etc/multipath.conf
# vi /etc/multipath.conf
blacklist {
devnode "^hda"
}
defaults {
user_friendly_names yes
path_grouping_policy multibus
failback immediate
no_path_retry fail
}
multipaths {
multipath {
wwid 14f504e46494c4552514a796e67642d786a4c642d42346271
alias sda
}
multipath {
wwid 14f504e46494c4552514a796e67642d786a4c642d42346271
alias sdb
}
}
說明1: 默認multipath會把所有設備都加入到黑名單,HDA本地磁盤與光驅,需要排除掉。
上面配置文件是因為本地磁盤是hda盤做的測試。
說明2: 配置文件修改為類似下面的內容,這裡禁止使用hda光驅,本地的sda磁盤。
devnode_blacklist {
devnode "^hda"
wwid 14f504e46494c4552514a796e67642d786a4c642d48346537
}
(4) 啟動服務
# service multipathd start
說明:
采用多路徑設備支持後,原來的/dev/sda,/dev/sdb設備名將不能再使用,改為/dev/mapper/mpathn,/dev/dm-n等名稱。
其中/dev/mapper/mpathn 是軟件虛擬出來的多路徑設備,這個可以被我們用來掛載使用。
其中/dev/mapper/sda 是多路徑設備別名,
其中/dev/dm-n 這個是軟件自身使用的,不可掛載使用。
# multipath -ll
sda (14f504e46494c4552514a796e67642d786a4c642d42346271) dm-2 OPNFILER,VIRTUAL-DISK
[size=2.0G][features=0][hwhandler=0][rw]
\_ round-robin 0 [prio=2][active]
\_ 0:0:0:0 sda 8:0 [active][ready]
\_ 1:0:0:0 sdb 8:16 [active][ready]
7. 掛載iSCSI設備
(1). 分區
說明: 由於采用multipath管理iscsi多路徑設備後,實際的設備名稱是/dev/mapper/sda, 可以再通過/dev/sda進行分區
但是進行格式化時會出現問題。
# fdisk /dev/sda
或采用
# fdisk /dev/mapper/sda
進行分區n p 1 w
(2). 格式化
# mkfs.ext3 /dev/sda1
mke2fs 1.39 (29-May-2006)
/dev/sda1 is apparently in use by the system; will not make a filesystem here!
1) 解決方法:
出現以上提示時也可以采用如下方式解決。之後就可以進行格式化操作了。
# dmsetup status
VolGroup00-LogVol01: 0 4128768 linear
sdb: 0 8388608 multipath 2 0 0 0 2 1 A 0 1 0 8:16 A 0 E 0 1 0 8:32 A 0
VolGroup00-LogVol00: 0 37552128 linear
# dmsetup remove_all
# dmsetup status
VolGroup00-LogVol01: 0 4128768 linear
VolGroup00-LogVol00: 0 37552128 linear
完成後需要重啟multipath服務
# service multipathd restart
2) multipath基本操作命令
# multipath -F #刪除現有路徑
# multipath -ll #查看多路徑
3) 實現開機時網絡掛載
# vi /etc/fstab
/dev/mapper/sdap1 /mnt/data ext3 _netdev 0 0
# chkconfig netfs --level 35 on
# service netfs start
或采用如下方式進行掛載:
------------------------------------------------------------
查看磁盤的UUID
# tune2fs -l /dev/sda1
.....
Filesystem UUID: c160af38-3928-42c8-9155-ac05a1d20538
# vi /etc/fstab
UUID=c160af38-3928-42c8-9155-ac05a1d20538 /mnt/data ext3 _netdev 0 0
------------------------------------------------------------
8. 故障處理
(1) 通過對openfiler的雙網卡進行故障測試
openfiler系統上down掉eth0後
# multipath -ll
sda: checker msg is "readsector0 checker reports path is down"
sda (14f504e46494c4552514a796e67642d786a4c642d42346271) dm-2 OPNFILER,VIRTUAL-DISK
[size=2.0G][features=0][hwhandler=0][rw]
\_ round-robin 0 [prio=1][active]
\_ 0:0:0:0 sda 8:0 [failed][faulty]
\_ 1:0:0:0 sdb 8:16 [active][ready]
openfiler系統上up 掉 eth0
# multipath -ll
sda (14f504e46494c4552514a796e67642d786a4c642d42346271) dm-2 OPNFILER,VIRTUAL-DISK
[size=2.0G][features=0][hwhandler=0][rw]
\_ round-robin 0 [prio=2][active]
\_ 0:0:0:0 sda 8:0 [active][ready]
\_ 1:0:0:0 sdb 8:16 [active][ready]
問題:
多路徑multipath在切換的時間會出現短時的無響應,multipath -ll命令會提示有一個路徑當掉,多次切換會出現掛載的分區出現文件系統只讀,重新掛載後正常。
[root@localhost iscsi]# cp aaa.txt ccc.txt
cp: cannot create regular file `ccc.txt': Read-only file system
(2) 刪除失效的iscsi 連接:
如果因為錯誤配置等原因創建了iscsi 對應,系統不會自動刪除,需手動刪除。
例如:
# iscsiadm -m node -o delete -T iqn.2006-01.com.openfiler:tsn.f9d59aaffe9c -p 192.168.100.238:3260
本文出自 “koumm的linux技術博客” 博客,請務必保留此出處http://koumm.blog.51cto.com/703525/1111163