首页 > 代码库 > iscis

iscis

iscis

 

iscsi概念

 

iSCSI(Internet SCSI)支持从客户端(发起端)通过IP向远程服务器上的SCSI存储设备(目标)发送SCSI命令。iSCSI限定名称用于确定发起端和目标,并采用iqn.yyyy-mm.{reversedomain}:label的格式。默认情况下,网络通信是至iSCSI目标上的端口3260/tcp的明文。

1 iSCSI发起端:需要访问原始SAN存储的客户端。

2 iSCSI目标:从iSCSI服务器提供的远程硬盘磁盘,或“目标门户”

3 iSCSI目标门户:通过网络向发起端提供目标的服务器。

4 IQN:“iSCSI限定名称”。每个发起端和目标需要唯一名称进行标识,最好的做法是使用一个在Internet上可能独一无二的名称。

 

 

iscsi共享的是设备,samba和nfs共享的是文件系统。

 

iscsi目标配置

 

配置前的准备:建立一个lvm,因为lvm可扩展,便于储存。

 

 

1 安装iscsi目标软件包:

 

yum install -y targetcli

 

2 启动服务

 

systemctl enable target; systemctl start target

 

3 进入iSCSI目标交互式配置模式:

 

targetcli

 

/> cd /backstores/block

/backstores/block> help ###查看帮助###

/> ls

/> /backstores/block create server1storage /dev/vg0/iscsi_storage  ###创建一个块设备###

 

 

 

过程如下:

 

 

服务器

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

[root@server12 ~]# systemctl enable target.service

ln -s ‘/usr/lib/systemd/system/target.service‘ ‘/etc/systemd/system/multi-user.target.wants/target.service‘

[root@server12 ~]# targetcli

Warning: Could not load preferences file /root/.targetcli/prefs.bin.

targetcli shell version 2.1.fb34

Copyright 2011-2013 by Datera, Inc and others.

For help on commands, type ‘help‘.

 

/> 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]

/> cd /backstores/block

/backstores/block> help ###查看帮助###

 

/> /iscsi create iqn.2017-06.com.example:strage1###创建tpg。IQN:“iSCSI限定名称”。每个发起端和目标需要唯一名称进行标识,通常写法:iqn.年.月.域名反转:分享的target名称。如果想要授权target连接到特定节点,创建不同的target,每个target都有自己的target ID,也称为iqn ###

 

/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/luns create /backstores/block/server1storage ###将客户端看到的与真实的设备联系在一起###

 

/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/acls create iqn.2017-06.com.example:server1storagekey###对lun加密###

 

/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/portals create 172.25.12.11###创建端口###

 

/> exit###退出###

 

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 wil 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]

  - create name dev [readonly] [write_back]

  - delete name

  - exit

  - get [group] [parameter...]

  - help [topic]

  - ls [path] [depth]

  - pwd

  - refresh

  - set [group] [parameter=value...]

  - status

/backstores/block> ls

o- block .................................................. [Storage Objects: 0]

/backstores/block> cd

 

/backstores/block> cd /

/> 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]

/> /backstores/block create server1storage /dev/vg0/iscsi_storage  ###创建一个块设备###

Created block storage object server1storage using /dev/vg0/iscsi_storage.

/> /iscsi create iqn.2017-06.com.example:strage1###创建tpg。IQN:“iSCSI限定名称”。每个发起端和目标需要唯一名称进行标识,通常写法:iqn.年.月.域名反转:分享的target名称。如果想要授权target连接到特定节点,创建不同的target,每个target都有自己的target ID,也称为iqn ###

Created target iqn.2017-06.com.example:strage1.

Created TPG 1.

/> ls

o- / ..................................................................... [...]

  o- backstores .......................................................... [...]

  | o- block .............................................. [Storage Objects: 1]

  | | o- server1storage  [/dev/vg0/iscsi_storage (996.0MiB) write-thru deactivated]

  | o- fileio ............................................. [Storage Objects: 0]

  | o- pscsi .............................................. [Storage Objects: 0]

  | o- ramdisk ............................................ [Storage Objects: 0]

  o- iscsi ........................................................ [Targets: 1]

  | o- iqn.2017-06.com.example:strage1 ............................... [TPGs: 1]

  |   o- tpg1 ........................................... [no-gen-acls, no-auth]

  |     o- acls ...................................................... [ACLs: 0]

  |     o- luns ...................................................... [LUNs: 0]

  |     o- portals ................................................ [Portals: 0]

  o- loopback ..................................................... [Targets: 0]

/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/luns create /backstores/block/server1storage ###将客户端看到的与真实的设备联系在一起###

Created LUN 0.

/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/acls create iqn.2017-06.com.example:server1storagekey###对lun加密###

Created Node ACL for iqn.2017-06.com.example:server1storagekey

Created mapped LUN 0.

/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/portals create 172.25.12.11###创建端口###

Using default IP port 3260

Created network portal 172.25.12.11:3260.

/> exit

Global pref auto_save_on_exit=true

Last 10 configs saved in /etc/target/backup.

Configuration saved to /etc/target/saveconfig.json

[root@server12 ~]# systemctl stop firewalld

 

 

客户端:

 

1)

1 vim /etc/iscsi/initiatorname.iscsi

 

内容:

nitiatorName=iqn.2017-06.com.example:server1storagekey

 

 

2 systemctl restart iscsi

 

3 iscsiadm -m discovery -t st -p 172.25.12.11 ###使用iscsiadm命令来连接到iscsi target。iscaiadm有不同的模式,每一个模式用来处理iscsi连接的不同阶段。-m 指动作,用来发现iscsi target,-p 指端口,-t指类型。该命令不仅显示target的名字,并且将iscsi配置添加到/var/lib/iscsi/send_target目录下###

 

4 iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.12.11 -l ###node指登入到特定的iscsi target,-l指登入,该命令指登入到iqn.2017-06.com.example:strage1的iscsi target###

5 fdisk-l###成功建立连接后会发现多了一个磁盘,那便是远程服务器的磁盘,可以对其进行操作,划分分区,格式化###

 

 

 

 

2)查看iscsi配置

 

1 yum install tree -y ###tree命令可以创建文件列表,将所有文件以所有文件以树的形式列出来####

2  tree -C /var/lib/iscsi/###-C指在文件和目录清单上加上色彩,便于区分各种类型###

 

 

3)开机自动挂载

 

1. 使用blkid确定文件系统UUID并使用UUID挂载,而不是/dev/sd*设备名称。(每次

引导时显示的设备名称都不同,具体取决于iSCSI设备通过网络进行响应的顺序。

如果按设备名称挂载,这会导致使用错误的设备。)

 

2. 在/etc/fstab中使用_netdev作为挂载选项。(这将确保客户端不会尝试挂载文件系

,直至启用联网。否则,在引导时系统将出错。)

 

3. 确保iscsi服务在引导时启动。

 

具体操作:

1 vim  /etc/fstab

 

内容:

 

/dev/sda1的UUID=“ ”/mntxfsdefaults,_netdev00###该设备是一个网络设备,在开机时,要启动联网。###

 

2 mount-a

 

4)中断使用iscsi目标

 

确保没有使用目标所提供的任何设备。

确保从/etc/fstab等位置中删除使用目标的所有永久挂载。

登出iSCSI目标,以暂时断开连接。

删除iSCSI目标的本地记录,以永久断开连接。

 

 

具体操作:

 

1 fdisk  /dev/sda###删除分区###

2 vim/etc/fstab###删除写的自动挂载###

3 iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.12.11 -u###-u指登出###

 

4 iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.12.11 -o delete###删除本地记录###


iscis