设为首页 收藏本站
查看: 758|回复: 0

[经验分享] iSCSI远程块存储配置实验

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-9-23 08:57:58 | 显示全部楼层 |阅读模式
实验环境:RHEL7.0
                服务器端   server1.example.com  172.25.254.1

                客户端1       server2.example.com  172.25.254.2

                客户端2       server3.example.com  172.25.254.3


1. iSCSI概念

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


    iSCSI发起端:需要访问原始SAN存储的客户端。
    iSCSI目标:从iSCSI服务器提供的远程硬盘磁盘,或“目标门户”
    iSCSI目标门户:通过网络向发起端提供目标的服务器。
    IQN:“iSCSI限定名称”。每个发起端和目标需要唯一名称进行标识,最好的做法是使用一个在Internet上可能独一无二的名称

2.iSCSI目标配置实验
  《1》服务器端配置

    2.1添加硬盘新硬盘,不用格式化分区,用于做远程磁盘。

        我已经添加了一块磁盘vda


[iyunv@server1 ~]# fdisk -l
Disk /dev/vda: 8589 MB, 8589934592 bytes, 16777216 sectors
       分区不用格式化
[iyunv@server1 ~]# fdisk /dev/vda

[iyunv@server1 ~]# cat /proc/partitions
    2.2安装iSCSI目标软件包:
# yum install -y targetcli
    启动服务:
# systemctl enable target; systemctl start target
     2.3 进入iSCSI目标交互式配置模式:

[iyunv@server1 ~]# 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 server:disk /dev/vda1
Created block storage object server:disk using /dev/vda1.
/> /iscsi create iqn.2016-09.com.example.com:storage1
Created target iqn.2016-09.com.example.com:storage1.
Created TPG 1.
/> /iscsi/iqn.2016-09.com.example.com:storage1/tpg1/luns create /backstores/block/server:disk

/> /iscsi/iqn.2016-06.com.example:storage1/tpg1/acls create iqn.2016-06.com.example:key
Created Node ACL for iqn.2016-06.com.example:key
Created mapped LUN 0.
Created LUN 0.
/> /iscsi/iqn.2016-09.com.example.com:storage1/tpg1/portals create 172.25.254.1
Using default IP port 3260
Created network portal 172.25.254.1:3260.
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[iyunv@server1 ~]#

[iyunv@server1 ~]# netstat -antple|grep 3260    ###查看端口
tcp        0      0 172.25.254.1:3260       0.0.0.0:*               LISTEN      0          35120   
[iyunv@server1 ~]# firewall-cmd --permanent --add-port=3260/tcp  ##添加防火墙策略
[iyunv@server1 ~]# firewall-cmd --reload


    《2》客户端1访问ISCSI存储
     2.1 安装iSCSI发起端软件包:

[iyunv@server2 ~]# yum install iscsi-initiator-utils -y
    2.2 在/etc/iscsi/initiatorname.iscsi中设置发起端的IQN:


[iyunv@server2 ~]# vim /etc/iscsi/initiatorname.iscsi

    InitiatorName=iqn.2016-09.com.example:storage
    2.3 查找iSCSI服务器所提供的iSCSI目标(目标门户)


[iyunv@server2 ~]# iscsiadm -m discovery -t st -p 172.25.254.1
172.25.254.1:3260,1 iqn.2016-09.com.example.com:key
    2.4 登录服务器上的一个或多个iscsi目标


[iyunv@server2 ~]# systemctl restart iscsid
[iyunv@server2 ~]# iscsiadm -m node -T iqn.2016-06.com.example:storage1 -p 172.25.254.1 -l
Logging in to [iface: default, target: iqn.2016-06.com.example:storage1, portal: 172.25.254.1,3260] (multiple)
Login to [iface: default, target: iqn.2016-06.com.example:storage1, portal: 172.25.254.1,3260] successful.
[iyunv@server2 ~]# fdisk -l     ###查看,多了一块磁盘
Disk /dev/sdb: 4294 MB, 4294967296 bytes, 8388608 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
    2.5 挂载使用

[iyunv@server2 ~]# fdisk  /dev/sdb

[iyunv@server2 ~]# partprobe
[iyunv@server2 ~]# mkfs.xfs /dev/sdb1
[iyunv@server2 ~]# mount /dev/sdb1 /mnt/
[iyunv@server2 ~]# cd /mnt/
[iyunv@server2 mnt]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root  8.5G  3.0G  5.6G  35% /
devtmpfs               488M     0  488M   0% /dev
tmpfs                  498M   92K  497M   1% /dev/shm
tmpfs                  498M  7.0M  491M   2% /run
tmpfs                  498M     0  498M   0% /sys/fs/cgroup
/dev/sda1              497M  119M  379M  24% /boot
/dev/sdb1              4.0G   33M  4.0G   1% /mnt

[iyunv@server2 mnt]# ls
file1  file10  file2  file3  file4  file5  file6  file7  file8  file9

[iyunv@server2 mnt]# iscsiadm -m node -T iqn.2016-06.com.example:storage1 -p 172.25.254.1 -u   #登出iSCSI目标,以暂时断开连接。
Logging out of session [sid: 3, target: iqn.2016-06.com.example:storage1, portal: 172.25.254.1,3260]
Logout of [sid: 3, targ

[iyunv@server2 mnt]# iscsiadm -m node -T iqn.2016-06.com.example:storage1 -p 172.25.254.1 -o delete      ##彻底断开连接


        《3》客户端2访问ISCSI存储
[iyunv@server3 ~]# yum install iscsi-initiator-utils.x86_64 -y
[iyunv@server3 ~]# vim /etc/iscsi/initiatorname.iscsi
        InitiatorName=iqn.2016-06.com.example:key
[iyunv@server3 ~]# iscsiadm -m discovery -t st -p 172.25.254.1
172.25.254.1:3260,1 iqn.2016-06.com.example:storage1
[iyunv@server3 ~]# iscsiadm -m node -T iqn.2016-06.com.example:storage1 -p 172.25.254.1 -l
Logging in to [iface: default, target: iqn.2016-06.com.example:storage1, portal: 172.25.254.1,3260] (multiple)
Login to [iface: default, target: iqn.2016-06.com.example:storage1, portal: 172.25.254.1,3260] successful.
[iyunv@server3 ~]# fdisk -l      ###得到的磁盘已经是被分区格式化好的,可直接挂载使用
Disk /dev/sdb: 4294 MB, 4294967296 bytes, 8388608 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: 0x231cc8fa
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            8192     8388607     4190208   83  Linux
[iyunv@server3 ~]# mount /dev/sdb1   /mnt/
[iyunv@server3 ~]# cd /mnt/
[iyunv@server3 mnt]# ls   ###可以看到我们在客户大端1上创建的文件
file1  file10  file2  file3  file4  file5  file6  file7  file8  file9


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-276196-1-1.html 上篇帖子: rpmbuile 制作drbd RPM包 下篇帖子: CentOS7配置默认启动为图形界面
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表