设为首页 收藏本站
查看: 1109|回复: 0

[经验分享] CentOS 6.5 安装部署iSCSi共享存储

[复制链接]

尚未签到

发表于 2017-6-25 16:19:23 | 显示全部楼层 |阅读模式
  CentOS 6.5 安装部署iSCSi共享存储
  一、前言
  1、什么是iSCSI?
  iSCSI技术是一种由IBM公司研究开发的,是一个供硬件设备使用的可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够在诸如高速千兆以太网上进行路由选择。iSCSI技术是一种新储存技术,该技术是将现有SCSI接口与以太网络(Ethernet)技术结合,使服务器可与使用IP网络的储存装置互相交换资料。
  iSCSI:Internet 小型计算机系统接口 (iSCSI:Internet Small Computer System Interface)。
Internet 小型计算机系统接口(iSCSI)是一种基于 TCP/IP的协议,用来建立和管理 IP 存储设备、主机和客户机等之间的相互连接,并创建存储区域网络(SAN)。SAN 使得 SCSI 协议应用于高速数据传输网络成为可能,这种传输以数据块级别(block-level)在多个数据存储网络间进行。
    SCSI 结构基于客户/服务器模式,其通常应用环境是:设备互相靠近,并且这些设备由 SCSI 总线连接。iSCSI 的主要功能是在 TCP/IP 网络上的主机系统(启动器 initiator)和存储设备(目标器 target)之间进行大量数据的封装和可靠传输过程。此外,iSCSI 提供了在 IP 网络封装 SCSI 命令,且运行在 TCP 上。






  2、环境介绍:



    本次部署由3台物理机实现,具体信息分别为以下:

      a、iSCSI_Server:192.168.30.133

      b、iSCSI_Client1:192.168.30.131

      c、iSCSI_Client2:192.168.30.132

    需要用到的软件为:

      a、scsi-target-utils    # 提供Server端服务

      b、iscsi-initiator-utils   #提供Client服务


二、安装部署服务端,即iSCSI_Server



1、在服务端创建可共享的磁盘或卷;这里就新添加一块新磁盘做为共享;

查看新添加的硬盘:

    

  [iyunv@iSCSI_Server ~]# fdisk -l
  Disk /dev/sda: 32.2 GB, 32212254720 bytes
64 heads, 32 sectors/track, 30720 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000da3dc
  Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           2         501      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             502       30720    30944256   8e  Linux LVM
Partition 2 does not end on cylinder boundary.
  Disk /dev/sdb: 21.5 GB, 21474836480 bytes
64 heads, 32 sectors/track, 20480 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
  2、对硬盘进行分区并创建LVM卷:



[iyunv@iSCSI_Server ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x47756356.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): p      # 查看分区信息
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
64 heads, 32 sectors/track, 20480 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x47756356
Device Boot      Start         End      Blocks   Id  System
Command (m for help): n      #新建一个分区
Command action
e   extended
p   primary partition (1-4)
e                  # 新建一个逻辑分区
Partition number (1-4): 4     # 卷标为 4
First cylinder (1-20480, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-20480, default 20480):
Using default value 20480
Command (m for help): p     # 查看信息
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
64 heads, 32 sectors/track, 20480 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x47756356
Device Boot      Start         End      Blocks   Id  System
/dev/sdb4               1       20480    20971504    5  Extended
Command (m for help): n      # 新建逻辑卷
Command action
l   logical (5 or over)
p   primary partition (1-4)
l                  # 选择l,逻辑卷
First cylinder (1-20480, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-20480, default 20480):
Using default value 20480
Command (m for help): p      # 查看信息
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
64 heads, 32 sectors/track, 20480 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x47756356
Device Boot      Start         End      Blocks   Id  System
/dev/sdb4               1       20480    20971504    5  Extended
/dev/sdb5               1       20480    20971488   83  Linux
Command (m for help): w      # 保存
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks
[iyunv@iSCSI_Server ~]# partprobe /dev/sdb      # 使刚才的配置立即生效

  [iyunv@iSCSI_Server ~]# fdisk -l


  Disk /dev/sda: 32.2 GB, 32212254720 bytes
64 heads, 32 sectors/track, 30720 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000da3dc


  Device Boot Start End Blocks Id System
/dev/sda1   *           2         501      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             502       30720    30944256   8e  Linux LVM
Partition 2 does not end on cylinder boundary.


  Disk /dev/sdb: 21.5 GB, 21474836480 bytes
64 heads, 32 sectors/track, 20480 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x47756356


  Device Boot Start End Blocks Id System
/dev/sdb4               1       20480    20971504    5  Extended
/dev/sdb5               1       20480    20971488   83  Linux

  
[iyunv@iSCSI_Server ~]# cat /proc/partitions
major minor  #blocks  name
  8        0   31457280 sda
   8        1     512000 sda1
   8        2   30944256 sda2
   8       16   20971520 sdb
   8       20          1 sdb4
   8       21   20971488 sdb5
253        0   27795456 dm-0
253        1    3145728 dm-1
  #注:看到以上标黄的信息证明已经创建逻辑卷成功!
  接下来创建LVM卷
  [iyunv@iSCSI_Server ~]# pvcreate /dev/sdb5        # 创建PV
  Physical volume "/dev/sdb5" successfully created
[iyunv@iSCSI_Server ~]# vgcreate kvmvg /dev/sdb5     # 创建VG
  Volume group "kvmvg" successfully created
[iyunv@iSCSI_Server ~]# lvcreate -L 19G -n kvmlv kvmvg  # 创建LV
  Logical volume "kvmlv" created.
[iyunv@iSCSI_Server ~]# lvs                 # 查看
  LV      VG       Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_root VolGroup -wi-ao---- 26.51g                                                   
  lv_swap VolGroup -wi-ao----  3.00g                                                   
  kvmlv   kvmvg    -wi-a----- 19.00g                                                   
[iyunv@iSCSI_Server ~]#
  #注:看到以上标黄的信息证明已经创建成功!


  3、安装服务端软件:scsi-target-utils




[iyunv@iSCSI_Server ~]# yum -y install epel-release
[iyunv@iSCSI_Server ~]# yum -y install scsi-target-utils.x86_64


  4、配置iSCSI服务:




[iyunv@iSCSI_Server ~]# vim /etc/tgt/targets.conf
#### 在 40行后添加以下信息#######
<target iqn.2017-03.com.zlyang:kvm.iscsi>
  backing-store /dev/kvmvg/kvmlv      
  initiator-address 192.168.30.0/24
</target>
  注:
    iqn.2017-03.com.zlyang:kvm.iscsi : 为共享名
      iqn.2017-03.com.zlyang:kvm.iscsi  :共享卷名及路径
      initiator-address 192.168.30.0/24  :允许哪些地址访问




 5、启动服务




[iyunv@iSCSI_Server ~]# service tgtd start
Starting SCSI target daemon:                               [  OK  ]
[iyunv@iSCSI_Server ~]# chkconfig tgtd on
[iyunv@iSCSI_Server ~]# netstat -tnlt|grep 3260
  tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN
   tcp        0      0 :::3260                     :::*                        LISTEN      

  6、添加防火墙规则



[iyunv@iSCSI_Server ~]# iptables -I INPUT 4 -p tcp --dport 3260 -j ACCEPT
[iyunv@iSCSI_Server ~]# iptables-save
[iyunv@iSCSI_Server ~]# service iptables save
[iyunv@iSCSI_Server ~]# service iptables restart


三、安装Client



  因为两台Client配置几乎一样,在此以Client1为例给大家演示具体部署过程

  

  1、首先查看本地磁盘

 


[iyunv@iSCSI_Client_1 ~]# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes
64 heads, 32 sectors/track, 30720 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000da3dc
Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           2         501      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             502       30720    30944256   8e  Linux LVM
Partition 2 does not end on cylinder boundary.
Disk /dev/mapper/VolGroup-lv_root: 28.5 GB, 28462546944 bytes
255 heads, 63 sectors/track, 3460 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/mapper/VolGroup-lv_swap: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 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
  # 可以看出只有一块磁盘
  2、安装Client软件



[iyunv@iSCSI_Client_1 ~]# yum -y install epel-release
[iyunv@iSCSI_Client_1 ~]# yum -y install iscsi-initiator-utils.x86_64


  3、启动服务




[iyunv@iSCSI_Client_1 ~]# service iscsid start
[iyunv@iSCSI_Client_1 ~]# chkconfig iscsid on




  4、发现下iSCSI服务端




[iyunv@iSCSI_Client_1 ~]# iscsiadm -m discovery -t st -p 192.168.30.133
192.168.30.133:3260,1 iqn.2017-03.com.zlyang:kvm.iscsi
  5、挂载该磁盘
  a、加载磁盘



[iyunv@iSCSI_Client_1 ~]# iscsiadm -m node -T iqn.2017-03.com.zlyang:kvm.iscsi -p 192.168.30.133 -l
Logging in to [iface: default, target: iqn.2017-03.com.zlyang:kvm.iscsi, portal: 192.168.30.133,3260] (multiple)
Login to [iface: default, target: iqn.2017-03.com.zlyang:kvm.iscsi, portal: 192.168.30.133,3260] successful.
[iyunv@iSCSI_Client_1 ~]# echo "iscsiadm -m node -T iqn.2017-03.com.zlyang:kvm.iscsi -p 192.168.30.133 -l" >> /etc/rc.d/rc.local"
[iyunv@iSCSI_Client_1 ~]# fdisk -l

  Disk /dev/sdc: 20.4 GB, 20401094656 bytes
64 heads, 32 sectors/track, 19456 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
  注:看到此信息表示已经加载成功
  b、分区格式化



[iyunv@iSCSI_Client_1 ~]# mkfs.ext4 /dev/sdc
mke2fs 1.41.12 (17-May-2010)
/dev/sdc is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1245184 inodes, 4980736 blocks
249036 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
152 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[iyunv@iSCSI_Client_1 ~]#
  c、挂载到本地



[iyunv@iSCSI_Client_1 ~]# mount /dev/sdc /mnt
[iyunv@iSCSI_Client_1 ~]# echo "mount /dev/sdc /mnt" >> /etc/rc.d/rc.local
[iyunv@iSCSI_Client_1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
26G  2.6G   23G  11% /
tmpfs                 939M     0  939M   0% /dev/shm
/dev/sda1             477M   52M  400M  12% /boot
/dev/sdc               19G   44M   18G   1% /mnt
[iyunv@iSCSI_Client_1 ~]#
  Client_1的所有配置已经配置完成,Client_2配置与Client_1基本相同,只是Client_2不需要再分区格式化了,直接加载及挂载就可以!
  好了,部署已经全部完成,如果什么问题可以回复或发邮件到:DBA_Master@163.com

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-388071-1-1.html 上篇帖子: CentOS虚拟化尝试 下篇帖子: centos7配置网桥
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表