Red Hatの学習記録[RHCE] ISCSIリモートストレージブロック

iSCSIの

定義

SCSISmall Computer System Interface

iSCSI基づいて、インターネット小型コンピュータシステムインタフェース、あるTCP/IP契約が。スルーネットワークのシミュレーションSCSI高性能ローカルストレージ全スタックは、それによってデータ伝送とリモートブロック記憶デバイスの管理を提供します。

用語コンポーネント

ランチャー

iSCSIクライアントは、通常、ソフトウェア、あなたがスターターの一意の名前を与える必要があります(IQN)

目標

iSCSI以下からの用ストレージリソース、iSCSIサーバーおよびコンフィギュレーションへの接続。あなたは、ターゲットの一意の名前(IQN)を得なければなりません。サーバーは、同時に複数のターゲットを提供することができます。

ACL

ノード使用してアクセス制御エントリ、IQNイニシエータファンroot権限を検証するためにアクセス制限を。

発見

ターゲットを設定するには、ターゲットサーバのうちのクエリ

IQN

iSCSI修飾名、グローバル一意の名前は、イニシエータとターゲットを識別するための命名形式を強制します。

iqn.YYYY-MM.com.reversed.domain[:optional_string]

`iqn` 表示此名称将使用域作为其标识符
`YYYY-MM`拥有域名的第一个月
`com.reversed.domain`组织的逆向域名

ログイン

ブロックデバイスを言って開始するようにクライアントを認証する項目のリスト

LUN

論理ユニット番号。番号付きブロックデバイスターゲットに接続され、ターゲットによって使用されます。1つの以上の単一のターゲットLUNへの接続が、一般的にのみターゲットLUNがあるかもしれません

ノード

ことによって、任意のiSCSIイニシエータまたはターゲットIQN識別

ポータル

ターゲットまたはイニシエータにIPアドレスとポートを確立するための

TPG

ターゲットポータルグループ、特定のiSCSIターゲットのインタフェースIPアドレスのセットが耳を傾け、TCPポートします

iSCSIサービスを構築します

iSCSIターゲットは、Aを提供します

インストールtargetcli

[root@rhel1 ~]# yum install -y targetcli

新しいパーティションを作成します。

元の基礎の作成/dev/sdb7パーティションタイプがありますLinux LVM (8e)

[root@rhel1 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xed07c356

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760    5  Extended
/dev/sdb5            4096      413695      204800   83  Linux
/dev/sdb6          415744      825343      204800   83  Linux

Command (m for help): n
Partition type:
   p   primary (0 primary, 1 extended, 3 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 7
First sector (827392-20973567, default 827392): 
Using default value 827392
Last sector, +sectors or +size{K,M,G} (827392-20973567, default 20973567): +500M
Partition 7 of type Linux and of size 500 MiB is set

Command (m for help): t
Partition number (1,5-7, default 7): 
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xed07c356

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760    5  Extended
/dev/sdb5            4096      413695      204800   83  Linux
/dev/sdb6          415744      825343      204800   83  Linux
/dev/sdb7          827392     1851391      512000   8e  Linux LVM

Command (m for help): w
[root@rhel1 ~]# partprobe

論理ボリュームの作成

[root@rhel1 ~]# pvcreate /dev/sdb7
  Physical volume "/dev/sdb7" successfully created
[root@rhel1 ~]# vgcreate iSCSI /dev/sdb7
  Volume group "iSCSI" successfully created
[root@rhel1 ~]# 
[root@rhel1 ~]# lvcreate -n iSCSI1 -L 100M iSCSI 
  Logical volume "iSCSI1" created

ランtargetcli

対話モードに入った後

[root@rhel1 ~]# targetcli
/> ls
o- / .............................................................. [...]
  o- backstores ................................................... [...]
  | o- block ....................................... [Storage Objects: 0]
  | o- fileio ...................................... [Storage Objects: 0]
  | o- pscsi ....................................... [Storage Objects: 0]
  | o- ramdisk ..................................... [Storage Objects: 0]
  o- iscsi ................................................. [Targets: 0]
  o- loopback .............................................. [Targets: 0]
/> 

加えます块BLOCK

/> backstores/block create server_disk1 /dev/iSCSI/iSCSI1 
Created block storage object server_disk1 using /dev/iSCSI/iSCSI1.

共通の目標と設定IQN

/> iscsi/ create iqn.2019-11.com.node:control1
Created target iqn.2019-11.com.node:control1.
Created TPG 1.

ターゲットと設定するには、ランチャーを追加IQN

/> iscsi/iqn.2019-11.com.node:control1/tpg1/acls create iqn.2019-11.com.node:control2
Created Node ACL for iqn.2019-11.com.node:control2
# 一会客户端会通过iqn.2019-11.com.node:control2这个IQN连接过来

ターゲット割り当てLUN論理ユニットを

/> iscsi/iqn.2019-11.com.node:control1/tpg1/luns create /backstores/block/server_disk1 
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2019-11.com.node:control2
# 也就是说连接到这个目标就可以使用这个块设备了。可以配置多个

ポータルの設定

/> iscsi/iqn.2019-11.com.node:control1/tpg1/portals create 192.168.143.10Using default IP port 3260
Created network portal 192.168.143.10:3260.
# 配置当前服务器IP 端口号默认3260可以更换

設定して終了保存

/> saveconfig
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

サービスを開始し、解放するファイアウォール

[root@rhel1 ~]# firewall-cmd --add-port=3260/tcp --permanent 
success
[root@rhel1 ~]# firewall-cmd --add-port=3260/tcp 
success
[root@rhel1 ~]# systemctl start target
[root@rhel1 ~]# systemctl enable target
ln -s '/usr/lib/systemd/system/target.service' '/etc/systemd/system/multi-user.target.wants/target.service'

ビューステータス

[root@rhel1 ~]# netstat -tunpl | grep 3260
tcp        0      0 192.168.143.10:3260     0.0.0.0:*               LISTEN      -       

iSCSIの設定クライアント

使用して、RHEL2クライアントとして動作します

コンフィギュレーション

# 安装
[root@rhel2 ~]# yum install iscsi*
# 启动
[root@rhel2 ~]# systemctl restart iscsi
[root@rhel2 ~]# systemctl enable iscsi
# 配置
### 此处添加的是服务器那边配置的ACL的IQN
[root@rhel2 ~]# cat /etc/iscsi/initiatorname.iscsi 
InitiatorName=iqn.2019-11.com.node:control2

使用

# 查看服务端的target
[root@rhel2 ~]# iscsiadm -m discovery -t st -p 192.168.143.10
192.168.143.10:3260,1 iqn.2019-11.com.node:control1
# 操作前查看一下当前disk只有/dev/sda
[root@rhel2 ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c979f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     4810751     2097152   82  Linux swap / Solaris
/dev/sda3         4810752    41943039    18566144   83  Linux

# 登录到这个target上
[root@rhel2 ~]# iscsiadm -m node -T iqn.2019-11.com.node:control1 -l
Logging in to [iface: default, target: iqn.2019-11.com.node:control1, portal: 192.168.143.10,3260] (multiple)
Login to [iface: default, target: iqn.2019-11.com.node:control1, portal: 192.168.143.10,3260] successful.
# 再次查看disk 多了/dev/sdb
[root@rhel2 ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c979f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     4810751     2097152   82  Linux swap / Solaris
/dev/sda3         4810752    41943039    18566144   83  Linux

Disk /dev/sdb: 104 MB, 104857600 bytes, 204800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes

パーティション、マウント構成

  • パーティション
[root@rhel2 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x0eb5d0ea.

Command (m for help): p

Disk /dev/sdb: 104 MB, 104857600 bytes, 204800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes
Disk label type: dos
Disk identifier: 0x0eb5d0ea

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
First sector (8192-204799, default 8192): 
Using default value 8192
Last sector, +sectors or +size{K,M,G} (8192-204799, default 204799): 50^H
Value out of range.
Last sector, +sectors or +size{K,M,G} (8192-204799, default 204799): +50M
Partition 1 of type Linux and of size 52 MiB is set

Command (m for help): p

Disk /dev/sdb: 104 MB, 104857600 bytes, 204800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes
Disk label type: dos
Disk identifier: 0x0eb5d0ea

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            8192      114687       53248   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@rhel2 ~]# partprobe
[root@rhel2 ~]# 
  • フォーマット
[root@rhel2 ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=4096 blocks
13328 inodes, 53248 blocks
2662 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33685504
7 block groups
8192 blocks per group, 8192 fragments per group
1904 inodes per group
Superblock backups stored on blocks: 
    8193, 24577, 40961

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
  • 設定は自動的にマウント
# 查看uuid
[root@rhel2 ~]# blkid /dev/sdb1
/dev/sdb1: UUID="eff8388b-2e93-4501-bf74-60bd870b5192" TYPE="ext4" 
# 编辑/etc/fstab文件
####################一定要加上`,_netdev`##########################
[root@rhel2 ~]# tail -1 /etc/fstab 
UUID=eff8388b-2e93-4501-bf74-60bd870b5192 /allow ext4 defaults,_netdev 0 0 
[root@rhel2 ~]# mkdir /allow
[root@rhel2 ~]# mount -a 
[root@rhel2 ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda3      xfs        18G  1.4G   17G   8% /
devtmpfs       devtmpfs  909M     0  909M   0% /dev
tmpfs          tmpfs     914M     0  914M   0% /dev/shm
tmpfs          tmpfs     914M  8.6M  905M   1% /run
tmpfs          tmpfs     914M     0  914M   0% /sys/fs/cgroup
/dev/sda1      xfs       297M   85M  213M  29% /boot
/dev/sr0       iso9660   3.5G  3.5G     0 100% /mnt
/dev/sdb1      ext4       47M  1.1M   42M   3% /allow
# 可以重启试一下 是否自动挂载
### 注意重启话先退出iscsi的登录
[root@rhel2 ~]# iscsiadm -m node -T iqn.2019-11.com.node:control1 -u 
Logging out of session [sid: 1, target: iqn.2019-11.com.node:control1, portal: 192.168.143.10,3260]
Logout of [sid: 1, target: iqn.2019-11.com.node:control1, portal: 192.168.143.10,3260] successful.

おすすめ

転載: www.cnblogs.com/primadonna/p/11961824.html