Centos下配置iscsi 共享存储
ISCSI存储分为服务端(server,提供target存储给客户端挂载使用)和客户段(client,使用服务端提供的target来存放文件等),Centos6.8下对应的agent为scsi-target-utils(服务端安装)和iscsi-initiator(客户端安装),以下的安装,全部是用虚拟机安装的。
我们在搭建RAC的时候会用到iscsi来构建共享存储,下面就介绍利用iscsi 怎样构建RAC的共享存储.
1. 环境信息
rac1:192.168.180.2
rac2:192.168.180.3
这里我们选rac1为iscsi服务器,然后把其上的磁盘共享给rac2使用
注意:这里我们可以选用这个2个节点任何一台或者其他机器作为iscsi服务器,这里为了方便就在rac1上搭建iscsi服务器
首先我们在rac1上添加需要共享的磁盘,也就是rac的磁盘组。这里我已经在rac1上分配了6块盘,说明如下:
Ocrvotedisk 3块 4G
Data 2块 50G
FRA_ARC 1 块 60G
在rac1上查看:
[root@rac1 ~]# fdisk -l
Disk /dev/sda: 64.4 GB,64424509440 bytes
255 heads, 63sectors/track, 7832 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:0x0000d707
Device Boot Start End Blocks Id System
/dev/sda1 1 5222 41943040 83 Linux
/dev/sda2 * 5222 6528 10485760 83 Linux
/dev/sda3 6528 7293 6144000 82 Linux swap / Solaris
Disk /dev/sdb: 4294 MB,4294967296 bytes
255 heads, 63sectors/track, 522 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
Disk /dev/sdd: 4294 MB,4294967296 bytes
255 heads, 63sectors/track, 522 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
Disk /dev/sde: 53.7 GB,53687091200 bytes
255 heads, 63sectors/track, 6527 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
Disk /dev/sdf: 53.7 GB,53687091200 bytes
255 heads, 63sectors/track, 6527 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
Disk /dev/sdg: 64.4 GB,64424509440 bytes
255 heads, 63sectors/track, 7832 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
Disk /dev/sdc: 4294 MB,4294967296 bytes
255 heads, 63sectors/track, 522 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
以上说明磁盘已经在rac1上挂载上,下面就利用iscsi 共享给rac2
2.配置iscsi服务端(在rac1上操作)
a)安装scsi-target-utils
[root@rac1 os]# ll scsi-target-utils-1.0.24-18.el6.x86_64.rpm
[root@rac1 os]# rpm -ivh scsi-target-utils-1.0.24-18.el6.x86_64.rpm
注意:在安装的时候有可能提示缺少依赖包,先将这些依赖包安装上以后就可以了
b)配置targets.conf
[root@rac1 os]# vi /etc/tgt/targets.conf
注意:里面添加的就是想要共享给rac2的磁盘
c)启动tgtd
[root@rac1 os]# servicetgtd start
Starting SCSI targetdaemon: [ OK ]
[root@rac1 os]# chkconfigtgtd on
3.配置iscsi客户端(在rac2上操作)
a)安装iscsi-initiator-utils
[root@rac2 Packages]# ll iscsi-initiator-utils-6.2.0.873-21.el6.x86_64.rpm
-r--r--r-- 3 root root747940 May 12 2016iscsi-initiator-utils-6.2.0.873-21.el6.x86_64.rpm
[root@rac2 Packages]# rpm -ivh iscsi-initiator-utils-6.2.0.873-21.el6.x86_64.rpm
b)配置nitiatorname.iscsi
[root@rac2 Packages]# vi /etc/iscsi/initiatorname.iscsi
注意:红框中的值就是rac1上 /etc/tgt/targets.conf 里配置的值
c)启动iscsi
[root@rac2 Packages]#service iscsi start
[root@rac2 Packages]#chkconfig iscsi on
注意:如果我安装操作系统时已经安装了iscsi-initiator-utils软件包所以不用再另外安装,直接配置就行。
4.共享存储(rac2上操作)
a)通过3260端口查看开放了哪些共享存储:
[root@rac2 ~]# iscsiadm -m discovery -tsendtargets -p 192.168.180.2:3260
192.168.180.2:3260,1 iqn.2008-09.com.example:server.target4
[root@rac2 ~]# iscsiadm -m node -T discovery -T iqn.2008-09.com.example:server.target4 -p 192.168.180.2:3260
b)登录共享存储:
# iscsiadm -m node -T iqn.2008-09.com.example:server.target4 -p 192.168.180.2:3260 -l
c)探测下共享存储的目录:
# partprobe
# fdisk -l
d)退出共享存储目录:
# iscsiadm -m node -T iqn.2008-09.com.example:server.target4 -p 192.168.1.251:3260 -u
# fdisk -l (将查看不到共享目录)
e)删除共享存储目录:
# service iscsi restart
# iscsiadm -m node -T iqn.2008-09.com.example:server.target4 -p 192.168.0.13:3260 -u
# iscsiadm -m node -T iqn.2008-09.com.example:server.target4 -p 192.168.0.13:3260 -o delete
f)重新服务并重新创建登录:
# service iscsi restart
# iscsiadm -m discovery -t sendtargets -p 192.168.180.2:3260
# iscsiadm -m node -T iqn.2008-09.com.example:server.target4 -p 192.168.0.13:3260 -l
g)为共享存储分区创建目录
# fdisk -l 我们发现多了一个sdb
然后就是给这个虚拟硬盘sdb分区,然后挂载
#fdisk /dev/sdb
Command (m for help): 在这里按m,就会输出帮助;
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition 注:这是删除一个分区的动作;
l list known partition types 注:l是列出分区类型,以供我们设置相应分区的类型;
m print this menu 注:m 是列出帮助信息;
n add a new partition 注:添加一个分区;
o create a new empty DOS partition table
p print the partition table 注:p列出分区表;
q quit without saving changes 注:不保存退出;
s create a new empty Sun disklabel
t change a partition's system id 注:t 改变分区类型;
u change display/entry units
v verify the partition table
w write table to disk and exit 注:把分区表写入硬盘并退出;
x extra functionality (experts only) 注:扩展应用,专家功能;
# partprobe
# mkfs -t ext3 /dev/sdb1 这一步如果硬盘容量大的话可能会非常慢,时间比较长
# mkdir /mnt/class
# echo "/dev/sdb1 /mnt/class ext3 _netdev 0 0">>/etc/fstab
# mount /mnt/class
# dd if=/dev/zero f=myfile bs=1M count=10 (创建成功,可以使用)
h)卸载共享存储:
# umount /mnt/class/
# rmdir /mnt/class/
# iscsiadm -m node -T iqn.2008-09.com.example:server.target4:disk1 -p 192.168.0.13:3260 –u
# iscsiadm -m node -T iqn.2008-09.com.example:server.target4:disk1 -p 192.168.0.13:3260 -o delete
# service iscsi stop
# chkconfig iscsi off
*******************************************客户端配置结束****************************************