配置IP SAN服务器搭建iscsi(协议)存储系统

NAS网络存储:
NAS(Network Attached Storage),NAS服务器是连接在网络上,具备资料存储功能的服务器,一种专用数据存储服务器。网络附属存储基于标准网络协议(Tcp/IP)实现数据传输,为网络中的Windows / Linux /
Mac OS 等各种不同操作系统的计算机提供文件共享和数据备份。部分NAS系统还可以支持FTP, HTTP, SQL
SQLSERVER等等功能,比如说现在NAS品牌 群晖!

国内: 群晖Synology, 希捷, 西部数码, 威联通
国际: Netapp, OUO, Dell, EMC

专业开源NAS系统: freeNAS, nas4free, OpenMediaValut, [H群晖]
美国八大金刚: Cisco, IBM, Google, 高通, Intel, Apple, 甲骨文, Microsoft

NAS优点:1. I/O消耗由前端服务器转移到后端存储设备上
2. 扩展方便
NAS缺点:1. 以前网络会成为瓶颈, 但是现在使用10G光纤卡,就可以解决这个问题。

SAN存储:
存储区域网络(Storage Area Network and SAN Protocols,简写SAN,即存储区域网络,是一种高速网络,提供在计算机与存储系统之间的数据传输。存储设备是指一台或多台用以存储计算机数据的磁盘设备,通常指磁盘阵列。
SAN存储,采用网状通道(Fibre Channel ,简称FC)技术,通过FC交换机连接存储阵列和服务器主机,建立专用于数据存储的区域网络。
SAN由于其基础是一个专用网络,因此扩展性很强,不管是在一个SAN系统中增加一定的存储空间还是增加几台使用存储空间的服务器都非常方便。

SAN的存储类型:
IPSAN: 不同的网络上, 使用TCP/IP协议的iscsi协议封装构件的存储区域网络
FSCAN: 利用光纤线, 通过高速FC交换机构件的存储区域网络,。(scsi协议)

NAS与SAN的区别在两方面:
第一,从网络架构来说,本质区别在于:
NAS,直接使用TCP/IP传输数据。SAN使用SCSI或iSCSI协议传输数据。
第二,从文件读写实现方法上来说,本质区别在于:
NAS采用了NFS和 CIFS技术实现文件共享。说明NAS是基于操作系统的“文件级”读写操作。
SAN中计算机和存储间的接口是底层的块协议,它按照协议头的“块地址+偏移地址”来定位。共享的存储和前端的操作系统类型没有关系,任何服务器操作系统,都可以正常识别。

SAN存储架构图:
在这里插入图片描述
配置成功后: 存储设备被前端server直接识别为块设备,即硬盘。

配置一个IP SAN 存储服务器

IP-SAN的运行模式:C/S模式,工作端口3260
服务端:服务名-target Yunzu63.cn(目标,san存储服务器)
客户端:服务名-initator Yunzu62.cn Yunzu64.cn(发起人,realsever).

配置服务器端

安装target
[root@yunzu63 Desktop]# yum install -y scsi-target-utils

主配置文件:
[root@yunzu63 ~]# ls /etc/tgt/targets.conf

启动服务:
[root@yunzu63 ~]# /etc/init.d/tgtd start
[root@yunzu63 ~]# netstat -antup | grep 3260

新建存储分区: sda4 大小5G
[root@yunzu63 ~]# fdisk /dev/sda #划分出sda4分区
WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to
switch off the mode (command ‘c’) and change display units to
sectors (command ‘u’).
Command (m for help): p
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000b8b35
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 1301 10240000 83 Linux
/dev/sda3 1301 1428 1024000 82 Linux swap / Solaris
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Selected partition 4
First cylinder (1428-2610, default 1428):
Using default value 1428
Last cylinder, +cylinders or +size{K,M,G} (1428-2610, default 2610): +5G
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

[root@yunzu63 ~]#reboot 或者 partx -a /dev/sda #使分区生效,多执行几次即可

配置sda4共享:
1修改配置文件
[root@yunzu63 ~]# vim /etc/tgt/targets.conf #写入以下内容
下面这段内容是参考模板
75 #

注释:
default-driver iscsi #此配置文件默认全部注释,使用iscsi驱动

2启动服务
[root@yunzu63 Desktop]# systemctl restart tgtd
[root@yunzu63 Desktop]# netstat -antup | grep 3260或者tgt-admin –show查看状态
Target 1: iqn.2015-01.cn.yunzu.www:target_san1
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Readonly: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 5372 MB, Block size: 512
Online: Yes
Removable media: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/sda4
Backing store flags:
Account information:
ACL information: #允许哪些客户端可以访问
192.168.1.64

配置客户端: yunzu64

[root@yunzu64 ~]# yum install -y iscsi-initiator-utils
启动客户端服务:
[root@yunzu64 ~]# systemctl start iscsid #直接启动没有任何反应, 这里首先要发现target存储,再启动客户端服务,才有效
[root@yunzu64 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.63:3260
Starting iscsid: [ OK ]
192.168.1.63:3260,1 iqn.2018-01.cn.yunzu.www:target_san1
[root@yunzu64 ~]# /etc/init.d/iscsid status
iscsid (pid 2607) is running…

target存储服务器信息在客户端存储的位置:
[root@yunzu64 ~]# yum install -y tree #安装tree命令,用于查询树
[root@yunzu64~]# tree /var/lib/iscsi/ #发现target后,会在此目录先生成树结构
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
│ └── iqn.2015-01.cn.yunzu.www:target_san1
│ └── 192.168.1.63,3260,1
│ └── default
├── send_targets
│ └── 192.168.1.63,3260
│ ├── iqn.2015-01.cn.yunzu.www:target_san1,192.168.1.63,3260,1,default ->
/var/lib/iscsi/nodes/iqn.2015-01.cn.yunzu.www:target_san1/192.168.1.63,3260,1
│ └── st_config
├── slp
└── static

客户端服务启动关系

先启动iscsid,再启动iscsi,iscsi是根据/var/lib/iscsi/中发现的信息,识别设备
[root@yunzu64 ~]#systemctl start iscsid #先启动iscsid
[root@yunzu64 ~]# systemctl start iscsi # 根据/var/lib/iscsi/ 中发现的信息,识别设备
Stopping iscsi: [ OK ]
Starting iscsi: [ OK ]
关闭:
[root@yunzu64 ~]# systemctl stop iscsi
[root@yunzu64 ~]# systemctl stop iscsid

开机自动启动:
[root@yunzu64 ~]# chkconfig iscsi on
[root@yunzu64 ~]# chkconfig iscsid on

查看发现到新硬盘:
[root@yunzu64 ~]# ll /dev/sdb
brw-rw---- 1 root disk 8, 16 Jul 30 19:11 /dev/sdb

卸载,挂载存储设备
卸载
[root@yunzu64 ~]# iscsiadm -m node -T iqn.2018-01.cn.yunzu.www:target_san1 -u
Logging out of session [sid: 1, target: iqn.2015-01.cn.yunzu.www:target_san1, portal:
192.168.1.63,3260]
Logout of [sid: 1, target: iqn.2015-01.cn.yunzu.www:target_san1, portal: 192.168.1.63,3260]
successful.
[root@yunzu64 ~]# ls /dev/sdb #查看设备不存在
ls: cannot access /dev/sdb: No such file or directory
登录存储存储设备
[root@yunzu64 ~]# iscsiadm -m node -T iqn.2018-01.cn.yunzu.www:target_san1 -l
Logging in to [iface: default, target: iqn.2018-01.cn.yunzu.www:target_san1, portal:
192.168.1.63,3260] (multiple)
Login to [iface: default, target: iqn.2018-01.cn.yunzu.www:target_san1, portal: 192.168.1.63,3260]
successful.
[root@yunzu64 ~]# ls /dev/sdb
/dev/sdb

上面的方法看起来比较复杂,命令比较长,简单的通过服务卸载与登陆
卸载方法二:
[root@yunzu64 ~]# systemctl stop iscsi
Stopping iscsi: [ OK ]
[root@yunzu64 ~]# ls /dev/sdb
ls: cannot access /dev/sdb: No such file or directory
登录方法二:
[root@yunzu64 ~]# systemctl restart iscsi

彻底退出:
[root@yunzu64 ~]# systemctl stop iscsi
[root@yunzu64 ~]# rm -rf /var/lib/iscsi/*

实例1: 在yunzu64上对识别出来的硬盘,分区格式化,挂载使用。
[root@yunzu64 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.63:3260 #发现存储设备
[root@yunzu64 ~]# systemctl restart iscsid #登录存储
[root@yunzu64 ~]# systemctl restart iscsi
[root@yunzu64 ~]# ls /dev/sdb #发现sdb
/dev/sdb

分区格式化,挂载使用
[root@yunzu64 ~]# fdisk /dev/sdb #划分一个分区当作本地盘使用即可
[root@yunzu64 ~]# ll /dev/sdb* #查看分区
[root@yunzu64 ~]# mkfs.ext4 /dev/sdb1 #格式化分区
[root@yunzu64 ~]# mount /dev/sdb1 /opt/ #挂载使用
[root@yunzu64 ~]# cp /etc/passwd /opt/ #测试文件写入

例2: 在target服务端,再添加一个存储客户端:
添加如下内容:

[root@yunzu63 ~]# vim /etc/tgt/targets.conf

[root@yunzu63 ~]# systemctl restart tgtd
Stopping SCSI target daemon: initiators still connected [FAILED]
Starting SCSI target daemon: [FAILED]
解决:客户端退出一下
[root@yunzu64 ~]# umount /opt/ #客户端卸载
[root@yunzu64 ~]# systemctl stop iscsi #客户端停止服务,做了这两个,再启动服务器端,否则,数据损失丢弃清空的情况发生。

客户端退出后,再测试启动:
[root@yunzu63 ~]# /etc/init.d/tgtd restart
Stopping SCSI target daemon: [ OK ]
Starting SCSI target daemon: [ OK ]
[root@yunzu63 ~]# tgt-admin –show #查看情况

测试: yunzu64 和yunzu62 都挂载上硬盘,数据同步
[root@yunzu64 ~]# systemctl start iscsid
[root@yunzu64 ~]# systemctl start iscsi
[root@yunzu64 ~]# ls /dev/sdb*
/dev/sdb /dev/sdb1
[root@yunzu64 ~]# ls /dev/sdb*
/dev/sdb /dev/sdb1

[root@yunzu64 ~]# mount /dev/sdb1 /opt/
[root@yunzu64 ~]# cp /etc/passwd /opt/ #复制一些数据

测试:yunzu62 是否数据同步
[root@yunzu62 ~]# yum –y install iscsi-initiator-utils
[root@yunzu62 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.63:3260
192.168.1.63:3260,1 iqn.2018-01.cn.yunzu.www:target_san1
[root@yunzu62 ~]# systemctl restart iscsid
[root@yunzu62 ~]# systemctl restart iscsi
有时候环境和你操作的顺序问题,可能无法发现,重启一下SAN Server,然后两台客户端重新sendtargets一下,重新启动服务和挂载.
[root@yunzu62 ~]# ls /dev/sdb*
/dev/sdb /dev/sdb1
[root@yunzu62 ~]# mount /dev/sdb1 /opt/
[root@yunzu62 ~]#ls /opt/ #可以看到数据已经同步过来了
lost+found passwd

添加新数据测试同步:
yunzu62
[root@yunzu62 ~]# cp /etc/hosts /opt
[root@yunzu62 ~]# ls /opt
hosts lost+found passwd

yunzu64上查看:
[root@yunzu64 ~]# ls /opt
lost+found passwd
#passwd #只看到passwd
没有同步,是因为我们使用的ext4 文件系统,ext4文件系统不支持多个客户端同时使用。 使用GFS文件系统就可以同步。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值