主机是kvm宿主机,安装了虚拟化组件
编辑/etc/iscsi/iscsid.conf
[root@192 ~]# vi /etc/iscsi/iscsid.conf
node.session.auth.authmethod = CHAP
node.session.auth.username = admin
node.session.auth.password = 123456789123
discovery.sendtargets.auth.authmethod = CHAP
discovery.sendtargets.auth.username = admin
discovery.sendtargets.auth.password = 123456789123
[root@192 ~]# systemctl restart iscsid
[root@192 ~]# iscsiadm -m discovery -t st -p 192.168.0.20
iscsiadm: No portals found \\iscsi服务器上未添加权限,所以这里要先去服务器上添加本机的权限
[root@192 ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1994-05.com.redhat:335c72a789d \\把iqn添加到服务器
添加完成后重新扫描
[root@192 ~]# iscsiadm -m discovery -t st -p 192.168.0.20
192.168.0.20:3260,1 iqn.1991-05.com.microsoft:win-8olmgmomodt-192.168.10.5-target
192.168.20.20:3260,1 iqn.1991-05.com.microsoft:win-8olmgmomodt-192.168.10.5-target
挂载
[root@192 ~]# iscsiadm -m node -p 192.168.0.20 -l
Logging in to [iface: default, target: iqn.1991-05.com.microsoft:win-8olmgmomodt-192.168.10.5-target, portal: 192.168.0.20,3260] (multiple)
Login to [iface: default, target: iqn.1991-05.com.microsoft:win-8olmgmomodt-192.168.10.5-target, portal: 192.168.0.20,3260] successful.
[root@192 ~]# iscsiadm -m node -p 192.168.20.20 -l
Logging in to [iface: default, target: iqn.1991-05.com.microsoft:win-8olmgmomodt-192.168.10.5-target, portal: 192.168.20.20,3260] (multiple)
Login to [iface: default, target: iqn.1991-05.com.microsoft:win-8olmgmomodt-192.168.10.5-target, portal: 192.168.20.20,3260] successful.
运行fdisk查看
Disk /dev/sdb: 96.6 GB, 96636764160 bytes, 188743680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/sdc: 96.6 GB, 96636764160 bytes, 188743680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
已经发现两块新硬盘
安装多路径软件
[root@192 ~]# yum install device-mapper-multipath -y
加载多路径模块
[root@192 ~]# modprobe dm-multipath
[root@192 ~]# modprobe dm-round-robin
[root@192 ~]# modprobe dm-service-time
启动服务
[root@192 ~]# systemctl start multipathd.service
[root@192 ~]# multipath -ll
Dec 19 15:09:30 | /etc/multipath.conf does not exist, blacklisting all devices.
Dec 19 15:09:30 | A default multipath.conf file is located at
Dec 19 15:09:30 | /usr/share/doc/device-mapper-multipath-0.4.9/multipath.conf
Dec 19 15:09:30 | You can run /sbin/mpathconf to create or modify /etc/multipath.conf
[root@192 ~]# systemctl status multipathd.service
â— multipathd.service - Device-Mapper Multipath Device Controller
Loaded: loaded (/usr/lib/systemd/system/multipathd.service; enabled; vendor preset: enabled)
Active: inactive (dead)
Condition: start condition failed at Sat 2015-12-19 15:09:08 CST; 41s ago
ConditionPathExists=/etc/multipath.conf was not met
Dec 19 15:09:08 192.168.0.119 systemd[1]: Started Device-Mapper Multipath Device Controller.
发现服务没起来,原因是没有配置文件,按照上面的提示拷贝一份过去
[root@192 ~]# cp /usr/share/doc/device-mapper-multipath-0.4.9/multipath.conf /etc/multipath.conf
[root@192 ~]# systemctl start multipathd.service
[root@192 ~]# multipath -ll
mpatha (360003ff44dc75adc9d7f6d4a54e065f8) dm-4 MSFT ,Virtual HD
size=90G features='0' hwhandler='0' wp=rw
|-+- policy='service-time 0' prio=1 status=active
| `- 3:0:0:0 sdb 8:16 active ready running
`-+- policy='service-time 0' prio=1 status=enabled
`- 4:0:0:0 sdc 8:32 active ready running
已经看到了,然后编辑 /etc/multipath.conf,把设备重命名一下
加入如下内容
multipaths {
multipath {
wwid 360003ff44dc75adc9d7f6d4a54e065f8
alias kvm
}
}
blacklist {
devnode "sda"
}
重启服务
[root@192 ~]# systemctl restart multipathd.service
[root@192 ~]# multipath -ll
kvm (360003ff44dc75adc9d7f6d4a54e065f8) dm-4 MSFT ,Virtual HD
size=90G features='0' hwhandler='0' wp=rw
|-+- policy='service-time 0' prio=1 status=active
| `- 3:0:0:0 sdb 8:16 active ready running
`-+- policy='service-time 0' prio=1 status=enabled
`- 4:0:0:0 sdc 8:32 active ready running
运行fdisk查看就可以看到这样一块设备了
Disk /dev/mapper/kvm: 96.6 GB, 96636764160 bytes, 188743680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
如果此设备是第一次被挂载,需要如下操作
pvcreate /dev/mapper/kvm 创建物理卷
mkfs.ext4 /dev/mapper/kvm 格式化
如果是多台机器共享此设备,第二台就无需以上操作了,直接挂载即可
mount /dev/mapper/kvm /mnt/iscsi
开机自动加载
[root@192 ~]# vi /etc/fstab
/dev/mapper/kvm /mnt/iscsi ext4 _netdev 0 0
[root@192 ~]# mount -a
[root@192 ~]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos_192-root xfs 11G 1.5G 9.3G 14% /
devtmpfs devtmpfs 4.2G 0 4.2G 0% /dev
tmpfs tmpfs 4.2G 0 4.2G 0% /dev/shm
tmpfs tmpfs 4.2G 9.1M 4.2G 1% /run
tmpfs tmpfs 4.2G 0 4.2G 0% /sys/fs/cgroup
/dev/mapper/centos_192-home xfs 5.4G 34M 5.4G 1% /home
/dev/mapper/centos_192-data xfs 83G 34M 83G 1% /data
/dev/sda1 xfs 521M 140M 381M 27% /boot
tmpfs tmpfs 836M 0 836M 0% /run/user/0
/dev/mapper/kvm ext4 95G 16G 75G 17% /mnt/iscsi
重启验证