二、什么是 iSCSI
iSCSI(Internet Small Computer Systems Interface)是一种基于 TCP/IP 的存储网络协议,它允许通过以太网将 SCSI 命令从主机(Initiator)发送到存储设备(Target)。
换句话说,iSCSI 将传统 SAN 的光纤通道(FC)协议“搬”到了以太网,实现低成本、高兼容性的块级存储访问。
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
# 查看后端块设备列表
[root@iscsi-server ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdf 8:80 0 20G 0 disk
sdd 8:48 0 5G 0 disk
sdb 8:16 0 5G 0 disk
sr0 11:0 1 1024M 0 rom
sde 8:64 0 20G 0 disk
sdc 8:32 0 5G 0 disk
sda 8:0 0 50G 0 disk
├─sda2 8:2 0 49G 0 part
│ ├─ol-swap 252:1 0 2G 0 lvm [SWAP]
│ └─ol-root 252:0 0 47G 0 lvm /
└─sda1 8:1 0 1G 0 part /boot
[root@iscsi-server ~]#
3.3.2 targetcli获取帮助信息
[root@iscsi-server ~]# targetcli
targetcli shell version 2.1.51
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> help
GENERALITIES
============
This is a shell in which you can create, delete and configure
configuration objects.
The available commands depend on the current path or target
path you want to run a command in: different path have
different sets of available commands, i.e. a path pointing at
an iscsi target will not have the same availaible commands as,
say, a path pointing at a storage object.
The prompt that starts each command line indicates your
current path. Alternatively (useful if the prompt displays
an abbreviated path to save space), you can run the
pwd command to display the complete current path.
Navigating the tree is done using the cd command. Without
any argument, cd will present you with the full objects
tree. Just use arrows to select the destination path, and
enter will get you there. Please try help cd for navigation
tips.
COMMAND SYNTAX
==============
Commands are built using the following syntax:
[TARGET_PATH] COMMAND_NAME [OPTIONS]
The TARGET_PATH indicates the path to run the command from.
If ommited, the command will be run from your current path.
The OPTIONS depend on the command. Please use help
COMMAND to get more information.
AVAILABLE COMMANDS
==================
The following commands are available in the
current path:
- bookmarks action [bookmark]
- cd [path]
- clearconfig [confirm]
- exit
- get [group] [parameter...]
- help [topic]
- ls [path] [depth]
- pwd
- refresh
- restoreconfig [savefile] [clear_existing] [target] [storage_object]
- saveconfig [savefile]
- sessions [action] [sid]
- set [group] [parameter=value...]
- status
- version
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json
[root@iscsi-server ~]#
3.3.3 创建iSCSI磁盘
使用ls命令查看菜单结构
[root@iscsi-server ~]# targetcli
targetcli shell version 2.1.51
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/>
/> cd iscsi/iqn.2003-01.org.linux-iscsi.iscsi-server.x8664:sn.4dd2641889d2/tpg1/
/iscsi/iqn.20...641889d2/tpg1> set attribute authentication=0 demo_mode_write_protect=0 generate_node_acls=1 cache_dynamic_acls=1
Parameter demo_mode_write_protect is now '0'.
Parameter authentication is now '0'.
Parameter generate_node_acls is now '1'.
Parameter cache_dynamic_acls is now '1'.
/iscsi/iqn.20...641889d2/tpg1>
/> cd iscsi/iqn.2003-01.org.linux-iscsi.iscsi-server.x8664:sn.4dd2641889d2/tpg1/acls
/iscsi/iqn.20...9d2/tpg1/acls> create iqn.1988-12.com.oracle:42d4c41739ea
Created Node ACL for iqn.1988-12.com.oracle:42d4c41739ea
Created mapped LUN 0.
Created mapped LUN 1.
Created mapped LUN 2.
Created mapped LUN 3.
Created mapped LUN 4.
/iscsi/iqn.20...9d2/tpg1/acls> cd iqn.1988-12.com.oracle:42d4c41739ea/
/iscsi/iqn.20...:42d4c41739ea> set auth userid=root
Parameter userid is now 'root'.
/iscsi/iqn.20...:42d4c41739ea> set auth password=123456
Parameter password is now '123456'.
/iscsi/iqn.20...:42d4c41739ea> info
chap_password: 123456
chap_userid: root
wwns:
iqn.1988-12.com.oracle:42d4c41739ea
/iscsi/iqn.20...:42d4c41739ea>
3.3.8 创建Portals
管理员需要创建一个门户配置以指定监听 IP 地址和端口;如果未指定 IP 则默认使用 0.0.0.0 地址;如果未指定端口号则默认使用 3260 端口。