事前準備
OSインストール
Oracle Linux 7.2, 7.4をインストール
LVM作成
- 割り当てるディスク作成1
[root@host]# fdisk /dev/sdb
コマンド(m でヘルプ): p
Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ(最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別し: 0x5ff808af
デバイス ブート 始点 終点 ブロック Id システム
コマンド(m でヘルプ): u
Changing display/entry units to cylinders (DEPRECATED!).
コマンド(m でヘルプ): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
バーティション番号 (1-4, default 1): 1
最初 cylinder (1-6527, 最小値 1): 8
Last cylinder, +cylinders or +size{K,M,G} (8-6527, 初期値 6527):
初期値 6527 を使います。
Partition 1 of type Linux and of size 50 Gib is set
コマンド(m でヘルプ): p
Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ(最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x5ff808af
デバイス ブート 始点 終点 ブロック Id システム
/dev/sdb1 8 6527 52371900 83 Linux
コマンド(m でヘルプ): w
パーティションテーブルは変更されました!
ioctl() を呼び出してパーティションテーブルを再読込みします。
ディスクを同期しています。
- LVM用に変更
[root@host]# fdisk /dev/sdb
コマンド(m でヘルプ): u
Changing display/entry units to cylinders (DEPRECATED!).
コマンド(m でヘルプ): p
Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ(最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x5ff808af
デバイス ブート 始点 終点 ブロック Id システム
/dev/sdb1 8 6527 52371900 83 Linux
コマンド(m でヘルプ): t
Sekected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
コマンド(m でヘルプ): p
Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ(最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x5ff808af
デバイス ブート 始点 終点 ブロック Id システム
/dev/sdb1 8 6527 52371900 8e Linux LVM
- 作成したディスクの確認
[root@host]# fdisk -lu /dev/sdb
Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/0 サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x5ff808af
デバイス ブート 始点 終点 ブロック Id システム
/dev/sdb1 112455 104856254 52371900 8e Linux LVM
- LVMのRPMパッケージ確認
[root@host]# rpm -qa | grep lvm2
lvm2-2.02.130-5.el7.x86_64
lvm2-libs-2.02.130-5.el7.x86_64
lvm2-python-libs-2.02.130-5.el7.x86_64
- LUNをLVMで管理する物理ボリュームとして登録
## 作成
[root@host]# pvcreate /dev/sdb1
Physical Volume "/dev/sdb1" successfully created
## 確認
[root@host]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 ol lvm2 a-- 49.51g 44.00m
/dev/sdb1 lvm2 --- 49.95g 49.95g
/dev/sdc1 lvm2 --- 49.95g 49.95g
- 物理ボリュームからボリュームグループを作成
## 作成
[root@host]# vgcreate vg_data01 /dev/sdb1 /dev/sdc1
Volume group "vg_data01" successfully created
## 確認
[root@host]# vgs
VG #PV #LV #SN Attr VSize VFree
ol 1 2 0 wz--n- 49.51g 44.00m
vg_data01 1 0 0 wz--n- 49.94g 49.94g
- ボリュームグループに論理ボリュームを作成
### 作成
[root@host]# lvcreate -L 10G -n lv_data01 vg_data01
Logical volume "lv_data01" created.
### 確認
[root@host]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root ol -wi-ao---- 47.46g
swap ol -wi-ao---- 2.00g
lv_data01 vg_data01 -wi-a----- 10.00g
ちなみに今回はOracle12c検証用なので、以下のように作成してみた
### 作成
[root@host]# lvcreate -L 10G -n lv_data02 vg_data01
Logical volume "lv_data02" created.
[root@host]# lvcreate -L 5G -n lv_ocr01 vg_data01
Logical volume "lv_ocr01" created.
[root@host]# lvcreate -L 5G -n lv_ocr02 vg_data01
Logical volume "lv_ocr02" created.
[root@host]# lvcreate -L 5G -n lv_ocr03 vg_data01
Logical volume "lv_ocr03" created.
### 確認
[root@host]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root ol -wi-ao---- 47.46g
swap ol -wi-ao---- 2.00g
lv_data01 vg_data01 -wi-a----- 10.00g
lv_data02 vg_data01 -wi-a----- 10.00g
lv_ocr01 vg_data01 -wi-a----- 5.00g
lv_ocr02 vg_data01 -wi-a----- 5.00g
lv_ocr03 vg_data01 -wi-a----- 5.00g
iSCSIの設定
- ターゲットのRPMパッケージ確認
[root@host]# rpm -qa | grep targetcli
targetcli-2.1.fb41-3.el7.noarch
- ターゲットサービスの自動起動の有効化とサービスの起動
[root@host]# systemctl enable target.service
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
[root@host]#
[root@host]# systemctl start target.service
[root@host]#
-
iptablesサービスを使用するためにデフォルトのfirewalldサービスを停止する[^2]
[root@orast01 ~]# systemctl is-enabled firewalld
enabled
[root@orast01 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@orast01 ~]# systemctl is-enabled firewalld
disabled
[root@orast01 ~]# systemctl stop firewalld
[root@orast01 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
12月 30 04:46:28 orast01.oracle.test.jp systemd[1]: Starting firewalld - dynamic firewall daemon...
12月 30 04:53:15 orast01.oracle.test.jp systemd[1]: Started firewalld - dynamic firewall daemon.
12月 30 14:43:37 orast01.oracle.test.jp systemd[1]: Stopping firewalld - dynamic firewall daemon...
12月 30 14:43:38 orast01.oracle.test.jp systemd[1]: Stopped firewalld - dynamic firewall daemon.
12月 30 18:09:14 orast01.oracle.test.jp systemd[1]: Stopped firewalld - dynamic firewall daemon.
[^2]: セキュリティ設定をする場合は必要
:warning: 後で検証
- iptablesのRPMパッケージ確認
```console
[root@host]# rpm -qa | grep iptables-service
iptables-services-1.4.21-16.el7.x86_64
- /etc/sysconfig/iptablesに追記とサービス再起動
設定追記
[root@orast01 ~]# iptables -A INPUT -p tcp --dport 3260 -j ACCEPT
[root@orast01 ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
サービスの再起動
[root@host]# systemctl restart iptables.service
[root@orast01 ~]# iptables -nL
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:3260
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
サービスの自動起動を有効化
[root@orast01 ~]# systemctl is-enabled iptables
disabled
[root@orast01 ~]# systemctl enable iptables
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
[root@orast01 ~]# systemctl is-enabled iptables
enabled
- 論理ボリュームをiSCSIディスクとして公開
作成した論理ボリュームをバックエンドデバイスとして登録する。
nameオプションは、任意の登録名を指定する
iSCSIターゲットの設定項目
項目 | 説明 |
---|---|
バックエンドデバイス | iSCSIディスクとして公開するデバイス |
IQN (iSCSI Qualified Name) | iSCSIイニシエーターにつける固有名 |
ポータル | iSCSIイニシエーターのIPアドレスとポート番号 |
ACL | iSCSIディスクの接続を許可するクライアントの指定 |
[root@host]# targetcli /backstores/block create name=DATA01 dev=/dev/vg_data01/lv_data01_1
Created block storage object DATA01 using /dev/vg_data01/lv_data01_1.
- iSCSIターゲットに関する設定の確認
iSCSIターゲットに関する設定は、擬似的なディレクトリ構造にまとめられていて、lsサブコマンドで確認できる。
### 公開前
[root@host]# 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]
### 公開後
[root@host]# targetcli ls /
o- / ........................................................................ [...]
o- backstores ............................................................. [...]
| o- block ................................................. [Storage Objects: 1]
| | o- DATA01 ..... [/dev/vg_data01/lv_data01_1 (10.0GiB) Write-thru deactivated]
| o- fileio ................................................ [Storage Objects: 0]
| o- pscsi ................................................. [Storage Objects: 0]
| o- ramdisk ............................................... [Storage Objects: 0]
o- iscsi ........................................................... [Targets: 0]
o- loopback ........................................................ [Targets: 0]
- iSCSIターゲットのIQNを設定(任意)
IQNとして規定されたフォーマットに従う必要がある。
[root@host]# targetcli /iscsi create iqn.2016-09.com.example:host01
Created target iqn.2016-10.com.example:host01.
Created TPG 1.
Global pref auto_default_portal=true
Created default portal listening on all IPs (0.0.0.0). port 3260.
- バックエンドデバイスをIQNに紐づける
設定したIQNに対して、ポータル(接続を受け付けるサーバ側のIPアドレスとポート番号)が自動的に割り当てられる。
デフォルトでは、すべてのIPアドレスで接続を受け付けて、ポート番号には、TCP3210番を使用する。
登録したバックエンドデバイスをIQNに紐付けて、外部から接続可能にする。
[root@host]# targetcli /iscsi/iqn.2016-09.com.example:host01/tpg1/luns create /backstores/block/DATA01
Created LUN 0
Created LUN 0 -> 0 mapping in node ACL iqn.2016-09.com.example.:client01
接続できる古〜他を制限するため、雪像可能なクライアントを指定するACLを定義する。
クライアントが持つイニシエーターのIQNで、接続可能なクライアントを指定する。「iqn.2016-09.com.example:client01」というIQNのイニシエーターからの接続を許可している。
[root@host]# targetcli /iscsi/iqn.2016-09.com.example:host/tpg1/acls create iqn.2016-09.com.example:client01
Created Node ACL for iqn.2016-09.com.example:client01
- これまでの設定を確認
[root@host]# targetcli ls /
o- / ........................................................................ [...]
o- backstores ............................................................. [...]
| o- block ................................................. [Storage Objects: 1]
| | o- DATA01 ..... [/dev/vg_data01/lv_data01_1 (10.0GiB) Write-thru deactivated]
| o- fileio ................................................ [Storage Objects: 0]
| o- pscsi ................................................. [Storage Objects: 0]
| o- ramdisk ............................................... [Storage Objects: 0]
o- iscsi ........................................................... [Targets: 1]
| o- IQN.2016-09.com.example:host01 ................................... [TPGs: 1]
| o- tpg1 .............................................. [no-gen-acls, no-auth]
| o- acls ......................................................... [ACLs: 1]
| | o- iqn.2016-09.com.example:client01 .................... [Mapped LUNs: 1]
| | o-mapped_lun0 ................................ [lun0 block/DATA01 (rw)]
| o- luns ......................................................... [LUNs: 1]
| | o- lun0 ....................... [block/DATA01 (/dev/vg_data01/lv_data01)]
| o- portals ................................................... [Portals: 1]
| o- 0.0.0.0: 3260 ................................................... [OK]
o- loopback ........................................................ [Targets: 0]
※待受IPをデフォルトの0.0.0.0(all)だとtpgを追加できない。標準ポート(3260)を変更すると繋がらない
- 設定内容の保存
[root@host]# targetcli saveconfig
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
### 設定の保存
[root@host]# systemctl restart target.service
### ポートを追加したい
[root@orast01 ~]# targetcli /iscsi/iqn.2016-09.example:host/tpg1/portals create 192.168.0.1 3260
Using default IP port 3260
Created network portal <ストレージサーバのIP>:3260
### TPGを増やしたい
[root@orast01 ~]# targetcli /iscsi/iqn.2017-08.oratest.jp:orast01.oratest.jp create tpg2
### すべての設定を削除する場合
[root@host]# targetcli clearconfig confirm=True
All configuration cleared
### 特定の項目を削除
[root@host]# targetcli /iscsi.iqn.2016-09.com.example:host/tpg1/acls delete iqn.2016-09.com.example:client01
Deleted Node ACL iqn.2016-09.com.example:client01
- ソフトウェアイニシエーターに必要なRPMの確認
[root@host]# rpm -qa | grep iscsi
iscsi-initiator-utils-6.2.0.873-32.0.1.el7.x86_64
iscsi-initiator-utils-iscsiuio-6.2.0.823-32.0.1.el7.x86_64
libiscsi-1.9.0-6.el7.x86_64
- iscsidサービスの自動起動の有効化とサービスの起動
iscsidサービスは、バックエンドでiSCSIイニシエーターの処理を行う。
iscsiサービスは、システム起動時に、登録済みのiSCSIターゲットを自動認識する。
[root@host]# systemctl enable iscsid.service
Created symlink from /etc/systemd/system/multi-user.target.wants/iscsid.service to /usr/lib/systemd/system/iscsid.service.
[root@host]#
[root@host]# systemctl start iscsid.service
[root@host]#
[root@host]# systemctl status iscsid.service
●iscsid.service - Open-iSCSI
Loaded: loaded (/usr/lib/systemd/system/iscsid.service; enabled; vendor preset; disabled)
Active: active (runding) since 日 2016−09−25 22:15:57 JST; 10s ago
Docs: man:iscsid(8)
man:iscsiadm(8)
Process: 3371 ExecStart=/usr/sbin/iscsid (code=exited, status=0/SUCCESS)
Main PID: 3373 (iscsid)
CGroup: /system.slice/iscsid.service
∟3372 /user/sbin/iscsid
∟3373 /user/sbin/iscsid
9月 25 22:15:57 client01 systemd[1]: Starting Opne-iSCSI...
9月 25 22:15:57 client01 systemd[1]: Failed to read PID from file /var/run/iscsid.pid Inva...memt
9月 25 22:15:57 client01 iscsid[3372]: iSCSI daemon with pid=3373 started!
9月 25 22:15:57 client01 systemd[1]: Startd Open-iSCSI.
Hint: Some lines were ellipsized, use -l to show in full.
[root@host]# systemctl enable iscsi.service
[root@host]#
- iSCSIイニシエーターのIQNを設定
/etc/iscsi/initiatorname.iscsiにiSCSIターゲットのほうでACLに設定したIQN「iqn.2016-09.com.example:client01」を設定し、iscsidサービスを再起動して、設定を反映する。
[root@host]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2016-09.com.example:client01
[root@host]# systemctl restart iscsid.service
[root@host]#
- iSCSIターゲットを検索して、IQNの表示を確認
[root@host]# iscsiadm -m discovery -t st -p 192.168.1.1:3260
192.168.1.1:3260,1 iqn.2016-09.com.example:host01
[root@host]#
[root@host]# iscsiadm -m node -T iqn.2016-09.com.example:host01 -p 192.168.1.1:3260,1
- iSCSIターゲットにログイン
--login
Loggin in to [iface: default, target: iqn.2016-09.com.example:host01, portal: 192.168.1.1,3260] (multiple)
Login to [iface: default, target: iqn.2016-09.com.example:host01, portal: 192.168.1.1,3260] successful.
iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)
### 設定を見直す。
[root@host]# vim /etc/iscsi/initiatorname.iscsi
### ストレージ側で ターゲットの設定見直しと設定反映を試してみる
[root@host]# targetcli saveconfig -- ターゲットの設定保存
[root@host]# systemctl restart target.service -- ターゲットの設定反映
- iSCSIディスク確認
[root@host]# lsblk -s
NAME HCTL TYPE VENDOR MODEL REV TRAN
sda 30:0:0:0 disk VMware Virtual disk 1.0 spi
sdb 35:0:0:0 disk LIO-ORG DATA01 4.0 iscsi
- 認識しているiSCSIターゲットの確認
[root@host]# iscsiadm -m node
192.168.1.1,3260 iqn.2016-09.com.example:host01
- iSCSIターゲットからログアウト
[root@host]# iscsiadm -m node -T iqn.2016-09.com.example:host01 -p 192.168.1.1,3260 --logout
- iSCSIターゲットの認識を削除
[root@host]# iscsiadm -m node -o delete -T iqn.2016-09.com.example:host01 -p 192.168.1.1,3260
- iSCSIターゲットの認識を更新
[root@host ~]# iscsiadm -m node -T iqn.2016-09.com.example:host01 -R
Rescanning session [sid: 6, target: iqn.2016-09.com.example:host01, portal: 192.168.1.1,3260]
-
パーティションでLUNを分割したい場合に使用。丸っとすべて使わせる場合はSKIPしても大丈夫 ↩