CentOS 6.5インストール導入iSCSi共有ストレージ


CentOS 6.5インストール導入iSCSi共有ストレージ
一、前言
1、iSCSIとは?
iSCSI技術はIBM社が研究開発したもので、高速ギガビットイーサネットなどの道路選択を可能にするIPプロトコルの上位層で実行可能なハードウェアデバイス用のSCSI命令セットである.iSCSI技術は,既存のSCSIインタフェースとイーサネット(Ethernet)技術を組み合わせて,サーバがIPネットワークを利用した記憶装置と資料を交換できるようにする新しい記憶技術である.
iSCSI:Internetスモールコンピュータシステムインタフェース(iSCSI:Internet Small Computer System Interface).Internet小型コンピュータシステムインタフェース(iSCSI)は、IPストレージデバイス、ホスト、クライアントなどの相互接続を確立し、管理し、ストレージエリアネットワーク(SAN)を作成するためのTCP/IPベースのプロトコルである.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#サーバ側サービス提供
b、iscsi-initiator-utils#Clientサービス提供
二、導入サービス、すなわちiSCSI_をインストールするServer
1.サービス側で共有可能なディスクまたはボリュームを作成する;ここでは、共有として新しいディスクを追加します.
新しく追加したHDDを表示するには、次の手順に従います.
     
 
[root@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ボリュームを作成する:
[root@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 bytes64 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 1Last cylinder, +cylinders or +size{K,M,G} (1-20480, default 20480): Using default value 20480Command (m for help): p      #
 
Disk /dev/sdb: 21.5 GB, 21474836480 bytes64 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 1Last cylinder, +cylinders or +size{K,M,G} (1-20480, default 20480): Using default value 20480Command (m for help): p      #

Disk /dev/sdb: 21.5 GB, 21474836480 bytes64 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

[root@iSCSI_Server ~]# partprobe /dev/sdb      #
[root@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

[root@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


[root@iSCSI_Server ~]# pvcreate /dev/sdb5        # PV
Physical volume "/dev/sdb5" successfully created
[root@iSCSI_Server ~]# vgcreate kvmvg /dev/sdb5     # VG
Volume group "kvmvg" successfully created
[root@iSCSI_Server ~]# lvcreate -L 19G -n kvmlv kvmvg  # LV
Logical volume "kvmlv" created.
[root@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
[root@iSCSI_Server ~]#

# :                 !

3、サービス側ソフトウェアのインストール:scsi-target-utils
 
[root@iSCSI_Server ~]# yum -y install epel-release
[root@iSCSI_Server ~]# yum -y install scsi-target-utils.x86_64


4、iSCSIサービスの構成:
[root@iSCSI_Server ~]# vim /etc/tgt/targets.conf
####   40 #######

  backing-store /dev/kvmvg/kvmlv      
  initiator-address 192.168.30.0/24


注意:
  iqn.2017-03.com.zlyang:kvm.iscsi:共有名
    iqn.2017-03.com.zlyang:kvm.iscsi:共有ボリューム名とパス
    initiator-address 192.168.30.0/24:アクセスできるアドレス
 
5、サービスを開始する
[root@iSCSI_Server ~]# service tgtd start
[root@iSCSI_Server ~]# chkconfig tgtd on
[root@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、ファイアウォールルールの追加
[root@iSCSI_Server ~]# iptables -I INPUT 4 -p tcp --dport 3260 -j ACCEPT  
[root@iSCSI_Server ~]# iptables-save
[root@iSCSI_Server ~]# service iptables save
[root@iSCSI_Server ~]# service iptables restart


三、Clientのインストール
2台のClientはほぼ同じ構成なので、Client 1を例に具体的な導入手順を説明します.
  
1、まずローカルディスクを見る
 
[root@iSCSI_Client_1 ~]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes64 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


#ディスクが1つしかないことがわかります
2、Clientソフトウェアのインストール
[root@iSCSI_Client_1 ~]# yum -y install epel-release
[root@iSCSI_Client_1 ~]# yum -y install iscsi-initiator-utils.x86_64


3、サービスを開始する
[root@iSCSI_Client_1 ~]# service iscsid start
[root@iSCSI_Client_1 ~]# chkconfig iscsid on




4、iSCSIサービスの発見
[root@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、ディスクのロード
# 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.
# echo "iscsiadm -m node -T iqn.2017-03.com.zlyang:kvm.iscsi -p 192.168.30.133 -l" >> /etc/rc.d/rc.local"

[root@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、パーティションフォーマット
[root@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 groups3
2768 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, 
    4096000Writing 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.
[root@iSCSI_Client_1 ~]#


c、ローカルへのマウント
[root@iSCSI_Client_1 ~]# mount /dev/sdc /mnt
[root@iSCSI_Client_1 ~]# echo "mount /dev/sdc /mnt" >> /etc/rc.d/rc.local [root@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
[root@iSCSI_Client_1 ~]#


Client_1のすべての構成が完了しました.Client_2構成とClient_1基本的に同じですが、Client_2パーティションをフォーマットする必要はありません.直接ロードしてマウントすればいいです.
はい、デプロイはすべて完了しました.何か問題があれば、DBAに返信したり、メールを送ったりすることができます[email protected]