首页 > 其他 > 详细

iscsi服务

时间:2017-03-20 11:00:09      阅读:1237      评论:0      收藏:0      [点我收藏+]








server端准备:
fdisk -l /dev/vdb-------新建分区
(建议+2G)
partprobe-------刷新分区表
yum install targetrcli -y---------安装服务
systemctl start target---------打开服务
systemctl enable target---------开机启动
systemctl stop firewalld---------关闭火墙


[root@samba ~]# 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]
/> /backstores/block create westos:storage1 /dev/vdb1        ##给设备/dev/vdb1一个别名(westos:storage1)##
Created block storage object westos:storage1 using /dev/vdb1.
/> /iscsi create iqn.2017-03.com.westos.storage1    ##生成设备共享文件##
Created target iqn.2017-03.com.westos.storage1.
Created TPG 1.
/> /iscsi/iqn.2017-03.com.westos.storage1/tpg1/acls create iqn.2017-03.com.westos:key1        ##给共享设备生成一个key1##
Created Node ACL for iqn.2017-03.com.westos:key1
/> /iscsi/iqn.2017-03.com.westos.storage1/tpg1/luns create /backstores/block/westos:storage1             ##将该别名和共享设备关联起来,设备别名必须使用绝对路径##
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2017-03.com.westos:key1
/> /iscsi/iqn.2017-03.com.westos.storage1/tpg1/portals create 172.25.254.137            ##开放端口##
Using default IP port 3260
Created network portal 172.25.254.137: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@samba ~]#
 












客户端:
yum install iscsi-initiator-utils.i686 -y-------安装软件包
systemctl start iscsi--------启动服务
注:iscsid服务是管理现在的,如果iscsi总是起不来,启动iscsid服务也是可以的
vim /etc/iscsi/initiatorname.iscsi---------编写iscsi的一个相关配置文件,写入server端的key
systemctl reset iscsi--------重启iscsi服务
iscsiadm 命令:
-l --login    ##登陆节点(服务器)##
-p --portal=ip[:port]    #指定target服务的IP和端口(ping IP)##

-T --targetname=targetname    ##用于指定target的名字##

-u  --logout    ##登出节点(服务器)##

-o --op=OPEARTION    ##指定针对discoverydb数据库的操作,其仅能为new、delete、update、show和nonpersistent其中之一##

-m  --mode op    ##可用的mode有discovery, node, fw, host iface 和 session##
-t --type    #
#这里可以使用的类型为sendtargets(可简写为st)、slp、fw和 isns,此选项仅用于discovery模式,且目前仅支持st、fw和isns;其中st表示允许每个iSCSItarget发送一个可用target列表给initiator##

例如:
iscsiadm -m node -T iqn.2017-03.com.westos.storage1 -p 172.25.254.137 -l
iscsiadm -m node -T iqn.2017-03.com.westos.storage1 -u
iscsiadm -m node -T iqn.2017-03.com.westos.storage1 -o delete


client的实际操作:
[root@client ~]# systemctl start iscsi        ##开启iscsi服务##
Warning: Unit file of iscsi.service changed on disk, ‘systemctl daemon-reload‘ recommended.    ##iscsi服务开启报错,要求执行“systemctl daemon-reload”命令##
[root@client ~]# systemctl daemon-reload
[root@client ~]# systemctl start iscsi
[root@client ~]# vim /etc/iscsi/initiatorname.iscsi     ##编写iscsi的一个配置文件##
[root@client ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2017-03.com.westos:key1    ##server端的key##
[root@client ~]# systemctl restart iscsi    ##重启iscsi服务##
[root@client ~]# iscsiadm -m discovery -t st -p 172.25.254.137        ##发现server端可共享的设备##
[root@client ~]# iscsiadm -m node -T iqn.2017-03.com.westos.storage1 -p 172.25.254.137 -l    ##连接server端的共享设备##
Logging in to [iface: default, target: iqn.2017-03.com.westos.storage1, portal: 172.25.254.137,3260] (multiple)
Login to [iface: default, target: iqn.2017-03.com.westos.storage1, portal: 172.25.254.137,3260] successful.
[root@client ~]# fdisk -l    ##查看分区列表##

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 sectors    ##client原有设备/dev/vda##
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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors    ##client原有设备/dev/vdb##
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/sda: 2147 MB, 2147483648 bytes, 4194304 sectors    ##/dev/sda是client连接到的server端所共享的设备##
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@client ~]# fdisk /dev/sda     ##在磁盘/dev/sda上分区##
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 0x0b4727ba.

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-4194303, default 8192):
Using default value 8192
Last sector, +sectors or +size{K,M,G} (8192-4194303, default 4194303): +1G
Partition 1 of type Linux and of size 1 GiB is set

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@client ~]# fdisk -l

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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/sda: 2147 MB, 2147483648 bytes, 4194304 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: 0x0b4727ba

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            8192     2105343     1048576   83  Linux
[root@client ~]# mount /dev/sda1 /mnt        ##将设备/dev/sda1挂载到目录/mnt##
mount: /dev/sda1 is write-protected, mounting read-only
mount: unknown filesystem type ‘(null)‘
[root@client ~]# mkfs.xfs /dev/sda1    ##格式化/dev/sda1##
meta-data=/dev/sda1              isize=256    agcount=8, agsize=32768 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=262144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@client ~]# mount /dev/sda1 /mnt    ##挂载设备##
[root@client ~]# df
Filesystem              1K-blocks    Used Available Use% Mounted on
/dev/vda1                10473900 3226672   7247228  31% /
devtmpfs                   493408       0    493408   0% /dev
tmpfs                      508996     140    508856   1% /dev/shm
tmpfs                      508996   13348    495648   3% /run
tmpfs                      508996       0    508996   0% /sys/fs/cgroup
//172.25.254.137/westos   1038336   33056   1005280   4% /mnt        ##挂载失败##
[root@client ~]# umount /mnt    ##卸载原设备##
[root@client ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       10473900 3226672   7247228  31% /
devtmpfs          493408       0    493408   0% /dev
tmpfs             508996     140    508856   1% /dev/shm
tmpfs             508996   13348    495648   3% /run
tmpfs             508996       0    508996   0% /sys/fs/cgroup
[root@client ~]# mount /dev/sda1 /mnt        ##再次挂载##
[root@client ~]# df    
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       10473900 3226672   7247228  31% /
devtmpfs          493408       0    493408   0% /dev
tmpfs             508996     140    508856   1% /dev/shm
tmpfs             508996   13348    495648   3% /run
tmpfs             508996       0    508996   0% /sys/fs/cgroup
/dev/sda1        1038336   33056   1005280   4% /mnt        ##挂载成功##
[root@client ~]# umount /mnt        ##卸载/mnt##
[root@client ~]# iscsiadm -m discovery -t st -p 172.25.254.137       ##发现172.25.254.137的共享文件##
172.25.254.137:3260,1 iqn.2017-03.com.westos.storage1
[root@client ~]# iscsiadm -m node -T iqn.2017-03.com.westos.storage1 -u        ##登出iscsi目标,以暂时断开连接##
Logging out of session [sid: 1, target: iqn.2017-03.com.westos.storage1, portal: 172.25.254.137,3260]
Logout of [sid: 1, target: iqn.2017-03.com.westos.storage1, portal: 172.25.254.137,3260] successful.
[root@client ~]# fdisk -l

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 by              ##/dev/sda1删除成功##

[root@client ~]# systemctl restart iscsi    ##重启iscsi服务##
[root@client ~]# fdisk -l

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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/sda: 2147 MB, 2147483648 bytes, 4194304 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: 0x0b4727ba

   Device Boot      Start         End      Blocks   Id  System        ##/dev/sda1有回来了##
/dev/sda1            8192     2105343     1048576   83  Linux        
[root@client ~]# iscsiadm -m node -T iqn.2017-03.com.westos.storage1 -o delete        ##删除client接收到的server端的共享##
[root@client ~]# systemctl restart iscsi
[root@client ~]# fdisk -l

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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        ##重启iscsi服务后,/dev/sda1并未回来,删除成功##





iscsi服务

原文:http://12459513.blog.51cto.com/12449513/1908219

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!