重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
iSCSI (Internet Small Computer System Interface),这种将scsi节后与以太网技术相结合的新型存储技术,可以用来在网络中传输scsi节后的命令和数据,使得用户可以通过互联网方便地访问远程机提供的共享存储资源。
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:国际域名空间、网络空间、营销软件、网站建设、黄陂网站维护、网站推广。
使用raid,可以保证服务器端提供存储资源的稳定性和可用性,这里使用raid5。
# 创建md0
[root@localhost Desktop]# mdadm -Cv /dev/md0 -n 3 -l 5 -x 1 /dev/sd[b-e]
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 5238272K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
# 查看md0状态
[root@localhost Desktop]# mdadm -D /dev/md0
......
Layout : left-symmetric
Chunk Size : 512K
Name : localhost.localdomain:0 (local to host localhost.localdomain)
UUID : 9e7dc640:37bde867:d3926c0f:0565156e
Events : 20
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
4 8 48 2 active sync /dev/sdd
3 8 64 - spare /dev/sde
主机 | 系统 | ip |
---|---|---|
服务端 | rhel 7 | 192.168.137.10 |
# 安装
[root@localhost Desktop]# yum install targetd targetcli -y
# 启动,设置开机自启动
[root@localhost Desktop]# systemctl restart targetd
[root@localhost Desktop]# systemctl enable targetd
ln -s '/usr/lib/systemd/system/targetd.service' '/etc/systemd/system/multi-user.target.wants/targetd.service'
使用targetcli命令管理iscsi的配置,它提供了一个交互式的配置界面,类似fdisk命令
# 执行targetcli进入配置界面
[root@localhost Desktop]# 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 目录,将创建的md0添加到共享设备的“资源池”中,将文件重新命名为disk0
/> cd /backstores/block
/backstores/block> create disk0 /dev/md0
Created block storage object disk0 using /dev/md0.
/backstores/block> cd /
/> ls
o- / ..................................................................... [...]
o- backstores .......................................................... [...]
| o- block .............................................. [Storage Objects: 1]
| | o- disk0 ..................... [/dev/md0 (10.0GiB) write-thru deactivated]
| o- fileio ............................................. [Storage Objects: 0]
| o- pscsi .............................................. [Storage Objects: 0]
| o- ramdisk ............................................ [Storage Objects: 0]
o- iscsi ........................................................ [Targets: 0]
o- loopback ..................................................... [Targets: 0]
/>
iscsi target名称是由系统自动生成的,这是一串用于描述共享资源的唯一字符串,用户在扫描iscsi服务端时会显示这个target名称。
# 进入到/iscsi目录下,生成target名称,同时会创建一个同名的“目录”,来存放共享资源
/> cd iscsi
/iscsi> create
Created target iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.b7056110e01d.
Created TPG 1.
/iscsi> ls
o- iscsi ................................................ [Targets: 1]
o- iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.b7056110e01d [TPGs: 1]
o- tpg1 ................................... [no-gen-acls, no-auth]
o- acls .............................................. [ACLs: 0]
o- luns .............................................. [LUNs: 0]
o- portals ........................................ [Portals: 0]
/iscsi>
# 进入到新创建的目录中,将disk0添加到这个新目录
/iscsi> cd iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.b7056110e01d/tpg1/luns
/iscsi/iqn.20...01d/tpg1/luns> create /backstores/block/disk0
Created LUN 0.
iscsi协议是通过客户端名称进行验证的,用户在访问存储共享资源是不需要输入密码,只要iscsi客户端的名称与服务端中设置的访问控制列表中某一名称条目一致即可。acls参数目录用于存放能够访问iscsi服务端共享存储资源的客户端名称。
# 在iscsi服务端的配置文件中写入一串能够验证用户信息的名称,这里使用target名称,加上:client,这个是自己定义的字符串,具有唯一性即可
/iscsi/iqn.20...01d/tpg1/luns> cd ..
/iscsi/iqn.20...6110e01d/tpg1> cd acls
/iscsi/iqn.20...01d/tpg1/acls> create iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.b7056110e01d:client
Created Node ACL for iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.b7056110e01d:client
Created mapped LUN 0.
/iscsi/iqn.20...01d/tpg1/acls>
/iscsi/iqn.20...01d/tpg1/acls> cd ..
/iscsi/iqn.20...6110e01d/tpg1> cd portals
/iscsi/iqn.20.../tpg1/portals> create 192.168.137.10
Using default IP port 3260
Created network portal 192.168.137.10:3260.
/iscsi/iqn.20.../tpg1/portals> ls /
o- / ........................................................... [...]
o- backstores ................................................ [...]
| o- block .................................... [Storage Objects: 1]
| | o- disk0 ............. [/dev/md0 (10.0GiB) write-thru activated]
| o- fileio ................................... [Storage Objects: 0]
| o- pscsi .................................... [Storage Objects: 0]
| o- ramdisk .................................. [Storage Objects: 0]
o- iscsi .............................................. [Targets: 1]
| o- iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.b7056110e01d [TPGs: 1]
| o- tpg1 ................................. [no-gen-acls, no-auth]
| o- acls ............................................ [ACLs: 1]
| | o- iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.b7056110e01d:client [Mapped LUNs: 1]
| | o- mapped_lun0 ................... [lun0 block/disk0 (rw)]
| o- luns ............................................ [LUNs: 1]
| | o- lun0 ........................... [block/disk0 (/dev/md0)]
| o- portals ...................................... [Portals: 1]
| o- 192.168.137.10:3260 ................................ [OK]
o- loopback ........................................... [Targets: 0]
/iscsi/iqn.20.../tpg1/portals> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[root@localhost Desktop]# systemctl restart targetd
[root@localhost Desktop]# firewall-cmd --permanent --add-port=3260/tcp
success
[root@localhost Desktop]# firewall-cmd --reload
success
iscsi服务器端配置完成。
[root@localhost Desktop]# yum install iscsi-initiator-utils -y
编辑客户端中的initiator名称文件,把服务器端的访问控制列表名称填写进来(服务器端acls目录中自定义的名称),重启服务。
[root@localhost Desktop]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName= iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.b7056110e01d:client
[root@localhost Desktop]# systemctl restart iscsid
[root@localhost Desktop]# systemctl enable iscsid
口诀“先发现,在登陆,最后挂载并使用”。
iscsiadm 用于管理、查询、插入、更新或删除iscsi数据库配置文件的工具。
[root@localhost Desktop]# iscsiadm -m discovery -t st -p 192.168.137.10
192.168.137.10:3260,1 iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.b7056110e01d
使用iscsiadm命令
[root@localhost Desktop]# iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.b7056110e01d -p 192.168.137.10 --login
......
successful
登录成功后,会在客户端多出一块存储设备/dev/sdb(设备名可能不同),现在就可以对新设备进行分区,挂载使用了。
使用iscsiadm -u 将设备卸载
[root@localhost Desktop]# iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.b7056110e01d -p 192.168.137.10 -u