iscsi的基本设定

一、概念

SAN:可以通过某些特殊的接口或信道(SCSI或eSATA)来提供局域网内的所有机器进行磁盘访问,SAN提供的是磁盘给主机用,而NAS提供的是网络协议的文件系统(NFS或SMB)

iSCSI主要是通过TCP/IP的技术,将存储设备通过iSCSI target功能,做成可以提供磁盘的服务器端,在通过iSCSI initiator功能,做成能够挂载使用的iSCSI target的客户端,如此便可以通过iSCSI协议来进行磁盘的应用了。

iSCSI target就是存储设备端,存放磁盘或RAID的设备

iSCSI initiator:想要连接iSCSI target服务器,也就是要安装iSCSI initiator的相关功能后才能使用iSCSI target提供的磁盘。

使用场景:



服务端:

[root@server ~]# yum install targetcli -y
由于iSCSI要共享的硬件设备,在此要做出来一个分区,供共享使用:

/> /backstores/block create westos:storage1 /dev/vdb1
Created block storage object westos:storage1 using /dev/vdb1.

              ##将/dev/vdb1做成共享的分区

/> /iscsi create iqn.2017-12.com.example:storage1
Created target iqn.2017-12.com.example:storage1.
Created TPG 1.

              ##本机域名为server.example.com,反写域名是iSCSI的自由的共享定义

/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/acls create iqn.2017-12.com.example:westoskey
Created Node ACL for iqn.2017-12.com.example:westoskey

            ##构建一把钥匙,只有有这把钥匙的主机才可对此共享的分区进行使用

/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/luns create /backstores/block/westos:storage1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2017-12.com.example:westoskey

           ##将这把钥匙与共享的分区进行连接

/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/portals create 172.25.71.1
Using default IP port 3260
Created network portal 172.25.71.1:3260.

          ##建立端口

添加火墙策略:

[root@server ~]# firewall-cmd --permanent --add-port=3260/tcp                ##tcp协议的端口
success
[root@server ~]# firewall-cmd --reload
success


测试:

客户端

[root@client ~]# yum install iscsi-initiator-utils.i686 -y             

重启时遇到了这样的报错[root@client ~]# systemctl restart iscsid.service
Warning: Unit file of iscsid.service changed on disk, 'systemctl daemon-reload' recommended.
解决方法:

[root@client ~]# systemctl daemon-reload              ##就是让系统重新加载下,此时即可以重启服务

[root@client ~]# systemctl restart iscsid.service
[root@client ~]# systemctl restart iscsi
要将服务端设置的钥匙给客户端

[root@client ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2017-12.com.example:westoskey

重启服务:

[root@client ~]# systemctl restart iscsid.service              ##此服务是iscsi的上层服务,有时不重启此服务,直接重启
[root@client ~]# systemctl restart iscsi                                iscsi服务,会报错
发现目标:
[root@client ~]# iscsiadm -m discovery -t st -p 172.25.71.1   ##发现设备
172.25.71.1:3260,1 iqn.2017-12.com.example:storage1
也可:

[root@client ~]# iscsiadm -m discovery -t sendtargets -p 172.25.71.1
172.25.71.1:3260,1 iqn.2017-12.com.example:storage1
登陆

[root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.71.1:3260 -l 

##(可加ip,也可不加)

测试:

[root@client ~]# cat /proc/partitions
major minor  #blocks  name

 253        0   10485760 vda
 253        1   10484142 vda1
 253       16   10485760 vdb
 253       17     512000 vdb1
 252        0     507904 dm-0
   8        0    2097152 sda                       ##此为服务端共享的设备

实现客户端开机自动挂载:

先给共享的分区建立文件系统,然后实现自动挂载



在写文件策略时,共享的分区最好写该分区的uid,这样在fstab文件中不会发生可能出现的名字飘逸情况,此问题会导致系统不乏正常启动

[root@client ~]# vim /etc/fstab


[root@client ~]# mount -a
[root@client ~]# df
Filesystem         1K-blocks    Used Available Use% Mounted on
/dev/vda1           10473900 3233544   7240356  31% /
devtmpfs              481120       0    481120   0% /dev
tmpfs                 496708      80    496628   1% /dev/shm
tmpfs                 496708   13080    483628   3% /run
tmpfs                 496708       0    496708   0% /sys/fs/cgroup
/dev/mapper/vg0-vo    483670    2350    451829   1% /home
/dev/sda1            2082816   33056   2049760   2% /mnt

退出:

1、卸载

[root@client ~]# umount /mnt/

2、删除文件中的策略

3、退出登陆

[root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.71.1:3260 -u
在登陆时使用了端口,所以在退出登陆时,也要使用端口,登陆与退出必须成对出现
4、删除

[root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.71.1 -o delete

测试:


使用tree此命令来查看


尽量把此文件中的东西删除,否则在下次登陆时,会出现报错

服务端此分区的删除:

先将targetcli中将所有的策略清空。

/> clearconfig confirm=true
All configuration cleared


可以在服务端将分区建立成lvm模式的,在客户端有需求时,随时可以在服务端进行lvm扩展,以满足客户端的需求。

服务端:

做出一块lvm格式的分区

[root@server ~]# pvcreate /dev/vdb1
WARNING: dos signature detected on /dev/vdb1 at offset 510. Wipe it? [y/n] y
  Wiping dos signature on /dev/vdb1.
  Physical volume "/dev/vdb1" successfully created
[root@server ~]# vgcreate iscsi_vg /dev/vdb1
  Volume group "iscsi_vg" successfully created
[root@server ~]# lvcreate -l 500 -n iscsi_lv iscsi_vg
  Logical volume "iscsi_lv" created


在targetcli中加入策略

/> /backstores/block create westos:storage1 /dev/iscsi_vg/iscsi_lv
Created block storage object westos:storage1 using /dev/iscsi_vg/iscsi_lv.
/> /iscsi create iqn.2017-12.com.example:storage1
Created target iqn.2017-12.com.example:storage1.
Created TPG 1.
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/acls create iqn.2017-12.com.example.westoskey
Created Node ACL for iqn.2017-12.com.example.westoskey
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/luns create /backstores/block/westos:storage1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2017-12.com.example.westoskey
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/portals create 172.25.71.1
Using default IP port 3260
Created network portal 172.25.71.1:3260.



测试:

[root@client ~]# iscsiadm -m discovery -t st -p 172.25.71.1
172.25.71.1:3260,1 iqn.2017-12.com.example:storage1
[root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.71.1 -l
Logging in to [iface: default, target: iqn.2017-12.com.example:storage1, portal: 172.25.71.1,3260] (multiple)
Login to [iface: default, target: iqn.2017-12.com.example:storage1, portal: 172.25.71.1,3260] successful.

若客户端有更大的需求时,可以直接将服务端的lvm扩大即可,理论讲,可以无限扩大的,但实际上,最大为18eb,因为文件系统的gpt格式下,最大为18eb

扩展lvm


[root@server ~]# pvcreate /dev/vdb2
  Physical volume "/dev/vdb2" successfully created
[root@server ~]# vgextend iscsi_vg /dev/vdb2
  Volume group "iscsi_vg" successfully extended
[root@server ~]# lvextend -L 4000M /dev/iscsi_vg/iscsi_lv
  Extending logical volume iscsi_lv to 3.91 GiB
  Logical volume iscsi_lv successfully resized


客户端:

在企业运维中客户端是可以实现自动化扩大的,但在此需要手动扩展

在客户端先退出登陆,删除后重新进行登陆,

[root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.71.1 -u
Logging out of session [sid: 8, target: iqn.2017-12.com.example:storage1, portal: 172.25.71.1,3260]
Logout of [sid: 8, target: iqn.2017-12.com.example:storage1, portal: 172.25.71.1,3260] successful.
[root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.71.1 -o delete
在此登陆:


查看是否更新了大小




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值