RHEL7部署ISCSI TARGET服务器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RHEL7部署ISCSI TARGET服务器相关的知识,希望对你有一定的参考价值。

一、配置yum源

[[email protected] yum.repos.d]# vi /etc/yum.repos.d/local.repo 

[local]

name=local

baseurl=file:///mnt/media/

enable=1

gpgcheck=0


二、挂载光盘

[[email protected] yum.repos.d]# mkdir /mnt/media/

[[email protected] yum.repos.d]# mount /dev/cdrom /mnt/media/

mount: /dev/sr0 is write-protected, mounting read-only

[[email protected] yum.repos.d]# 


三、通过yum安装targetcli

[[email protected] yum.repos.d]# yum install targetcli

Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Resolving Dependencies

--> Running transaction check

---> Package targetcli.noarch 0:2.1.fb41-3.el7 will be installed

--> Processing Dependency: python-rtslib >= 2.1.fb41 for package: targetcli-2.1.fb41-3.el7.noarch

--> Processing Dependency: python-configshell for package: targetcli-2.1.fb41-3.el7.noarch

--> Running transaction check

---> Package python-configshell.noarch 1:1.1.fb18-1.el7 will be installed

--> Processing Dependency: pyparsing for package: 1:python-configshell-1.1.fb18-1.el7.noarch

--> Processing Dependency: python-urwid for package: 1:python-configshell-1.1.fb18-1.el7.noarch

---> Package python-rtslib.noarch 0:2.1.fb57-3.el7 will be installed

--> Processing Dependency: python-kmod for package: python-rtslib-2.1.fb57-3.el7.noarch

--> Running transaction check

---> Package pyparsing.noarch 0:1.5.6-9.el7 will be installed

---> Package python-kmod.x86_64 0:0.9-4.el7 will be installed

---> Package python-urwid.x86_64 0:1.1.1-3.el7 will be installed

--> Finished Dependency Resolution


Dependencies Resolved


==============================================================================================================================================

 Package                                 Arch                        Version                                 Repository                  Size

==============================================================================================================================================

Installing:

 targetcli                               noarch                      2.1.fb41-3.el7                          local                       61 k

Installing for dependencies:

 pyparsing                               noarch                      1.5.6-9.el7                             local                       94 k

 python-configshell                      noarch                      1:1.1.fb18-1.el7                        local                       67 k

 python-kmod                             x86_64                      0.9-4.el7                               local                       57 k

 python-rtslib                           noarch                      2.1.fb57-3.el7                          local                       88 k

 python-urwid                            x86_64                      1.1.1-3.el7                             local                      654 k


Transaction Summary

==============================================================================================================================================

Install  1 Package (+5 Dependent packages)


Total download size: 1.0 M

Installed size: 4.5 M

Is this ok [y/d/N]: y

Downloading packages:

----------------------------------------------------------------------------------------------------------------------------------------------

Total                                                                                                         2.7 MB/s | 1.0 MB  00:00:00     

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : python-kmod-0.9-4.el7.x86_64                                                                                               1/6 

  Installing : python-rtslib-2.1.fb57-3.el7.noarch                                                                                        2/6 

  Installing : pyparsing-1.5.6-9.el7.noarch                                                                                               3/6 

  Installing : python-urwid-1.1.1-3.el7.x86_64                                                                                            4/6 

  Installing : 1:python-configshell-1.1.fb18-1.el7.noarch                                                                                 5/6 

  Installing : targetcli-2.1.fb41-3.el7.noarch                                                                                            6/6 

local/productid                                                                                                        | 1.6 kB  00:00:00     

  Verifying  : python-rtslib-2.1.fb57-3.el7.noarch                                                                                        1/6 

  Verifying  : python-urwid-1.1.1-3.el7.x86_64                                                                                            2/6 

  Verifying  : 1:python-configshell-1.1.fb18-1.el7.noarch                                                                                 3/6 

  Verifying  : targetcli-2.1.fb41-3.el7.noarch                                                                                            4/6 

  Verifying  : pyparsing-1.5.6-9.el7.noarch                                                                                               5/6 

  Verifying  : python-kmod-0.9-4.el7.x86_64                                                                                               6/6 


Installed:

  targetcli.noarch 0:2.1.fb41-3.el7                                                                                                           


Dependency Installed:

  pyparsing.noarch 0:1.5.6-9.el7                 python-configshell.noarch 1:1.1.fb18-1.el7          python-kmod.x86_64 0:0.9-4.el7         

  python-rtslib.noarch 0:2.1.fb57-3.el7          python-urwid.x86_64 0:1.1.1-3.el7                  


Complete!

[[email protected] yum.repos.d]# 


四、使用fdisk -l查看一下需要分享的磁盘是否正常

[[email protected] ~]# fdisk -l


Disk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 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: 0x000cc61d


   Device Boot      Start         End      Blocks   Id  System

/dev/sda1            2048     8390655     4194304   82  Linux swap / Solaris

/dev/sda2   *     8390656   167772159    79690752   83  Linux


Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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 /dev/sdc: 5368 MB, 5368709120 bytes, 10485760 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


[[email protected] ~]# 


五、使用targetcli配置服务器

5、1先help一下,查看一下支持的命令有哪些

[[email protected] ~]# targetcli

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

targetcli shell version 2.1.fb41

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

  - clearconfig [confirm] 

  - exit 

  - get [group] [parameter...] 

  - help [topic] 

  - ls [path] [depth] 

  - pwd 

  - refresh 

  - restoreconfig [savefile] [clear_existing] 

  - saveconfig [savefile] 

  - sessions [action] [sid] 

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

  - status 

  - version 

/> 

5、2配置目标服务器的iqn

[[email protected] ~]# targetcli

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

targetcli shell version 2.1.fb41

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

  - clearconfig [confirm] 

  - exit 

  - get [group] [parameter...] 

  - help [topic] 

  - ls [path] [depth] 

  - pwd 

  - refresh 

  - restoreconfig [savefile] [clear_existing] 

  - saveconfig [savefile] 

  - sessions [action] [sid] 

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

  - status 

  - version 

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

/iscsi> create iqn.2016-10.com.server:001

Created target iqn.2016-10.com.server:001.

Created TPG 1.

Global pref auto_add_default_portal=true

Created default portal listening on all IPs (0.0.0.0), port 3260.

/iscsi> ls

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

  o- iqn.2016-10.com.server:001 .......................................................................................... [TPGs: 1]

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

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

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

      o- portals ...................................................................................................... [Portals: 1]

        o- 0.0.0.0:3260 ....................................................................................................... [OK]

/iscsi> 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: 1]

  | o- iqn.2016-10.com.server:001 ........................................................................................ [TPGs: 1]

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

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

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

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

  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]

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

/> cd backstores/

/backstores> ls

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

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

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

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

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

/backstores> cd  block 

/backstores/block> ls

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

/backstores/block> ?

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

  - delete name 

  - exit 

  - get [group] [parameter...] 

  - help [topic] 

  - ls [path] [depth] 

  - pwd 

  - refresh 

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

  - status 

/backstores/block> create lun0 /dev/sdb

Created block storage object lun0 using /dev/sdb.

/backstores/block> create lun1 /dev/sdc

Created block storage object lun1 using /dev/sdc.

/backstores/block> ls

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

  o- lun0 ............................................................................... [/dev/sdb (5.0GiB) write-thru deactivated]

  o- lun1 ............................................................................... [/dev/sdc (5.0GiB) write-thru deactivated]

/backstores/block> cd /

/> ls

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

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

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

  | | o- lun0 ........................................................................... [/dev/sdb (5.0GiB) write-thru deactivated]

  | | o- lun1 ........................................................................... [/dev/sdc (5.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-10.com.server:001 ........................................................................................ [TPGs: 1]

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

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

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

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

  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]

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

/> cd iscsi/iqn.2016-10.com.server:001/tpg1/luns 

/iscsi/iqn.20...001/tpg1/luns> ls

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

/iscsi/iqn.20...001/tpg1/luns> create /backstores/block/lun0

Created LUN 0.

/iscsi/iqn.20...001/tpg1/luns> create /backstores/block/lun1

Created LUN 1.

/iscsi/iqn.20...001/tpg1/luns> ls

o- luns .................................................................................................................. [LUNs: 2]

  o- lun0 .................................................................................................. [block/lun0 (/dev/sdb)]

  o- lun1 .................................................................................................. [block/lun1 (/dev/sdc)]

/iscsi/iqn.20...001/tpg1/luns> cd /

/> cd iscsi/iqn.2016-10.com.server:001/tpg1/acls 

/iscsi/iqn.20...001/tpg1/acls> create iqn.2016-10.com.microsoft:node1

Created Node ACL for iqn.2016-10.com.microsoft:node1

Created mapped LUN 1.

Created mapped LUN 0.

/iscsi/iqn.20...001/tpg1/acls> ls

o- acls .................................................................................................................. [ACLs: 1]

  o- iqn.2016-10.com.microsoft:node1 .............................................................................. [Mapped LUNs: 2]

    o- mapped_lun0 .......................................................................................... [lun0 block/lun0 (rw)]

    o- mapped_lun1 .......................................................................................... [lun1 block/lun1 (rw)]

/iscsi/iqn.20...001/tpg1/acls> 

/iscsi/iqn.20...001/tpg1/acls> cd /

/> saveconfig 

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

Configuration saved to /etc/target/saveconfig.json

/> 


六、查看targetcli的状态及端口号是否正常

[[email protected] ~]# systemctl is-active target.service 

active

[[email protected] ~]# netstat -tunlp|grep 3260

tcp        0      0 0.0.0.0:3260            0.0.0.0:*               LISTEN      - 


七、防火墙放行并设置开机启动

[[email protected] ~]# firewall-cmd --add-service=iscsi-target --permanent

success

[[email protected] ~]# systemctl enable target


八、可以使用windows或linux挂载并使用了


本文出自 “高家大少的技术库” 博客,请务必保留此出处http://gaopengju.blog.51cto.com/12830710/1947597

以上是关于RHEL7部署ISCSI TARGET服务器的主要内容,如果未能解决你的问题,请参考以下文章

RHEL7 配置iscsi服务端并实现客户端自动开机挂载

RHEL7 配置iSCSI模拟环境

Kylin v10---iscsi部署

vSphere虚拟化之外部存储部署(上)

配置iSCSI 服务端

Linux7/Centos7 ISCSI网络存储服务