您现在的位置是:首页 > 文章详情

基于linux下的iscsi网络磁盘共享

日期:2018-06-08点击:652

iSCSI 主要是通过 TCP/IP 的技术,将储存设备端通过 iSCSI target 功能,做成服务端,再通过 iSCSI initiator (iSCSI 初始化用戶) 功能,做成使用 iSCSI target 的用戶端。 客户端可以通过局域网连接服务器上的iSCSI 服务器,在本地虚拟出一块硬盘,以达到通过网络共享服务器硬盘的效果。

  • iSCSI target:就是储存设备端,它能够为用户提供可用的存储资源。
  • iSCSI客户端则是用户使用的软件,用于获取远程服务端的存储资源,

配置服务端

[root@server ~]# yum install targetcli -y //策略编写工具; [root@server ~]# systemctl start target //启动服务 [root@server ~]# fdisk /dev/vdb //建立一个2G普通分区; [root@server ~]# partprobe //刷新 [root@server ~]# targetcli //进入编辑环境: /> /backstores/block create westos:storage1 /dev/vdb1 //改名 Created block storage object westos:storage1 using /dev/vdb1. /> /iscsi create iqn.2018-06.com.example:storage1 //修改iscsi的共享名称 Created target iqn.2018-06.com.example:storage1. Created TPG 1. /> /iscsi/iqn.2018-06.com.example:storage1/tpg1/acls create iqn.2018-06.com.example:westoskey //加密;iqn:网络名称查询方式;每个发起端和目标需要唯一的名称;iqn 年月域名反写标签年月域名反写标签 Created Node ACL for iqn.2018-06.com.example:westoskey /> /iscsi/iqn.2018-06.com.example:storage1/tpg1/luns create /backstores/block/westos:storage1 //关联设备,创建一个链接,将共享与分区关联起来; Created LUN 0. Created LUN 0->0 mapping in node ACL iqn.2018-06.com.example:westoskey /> /iscsi/iqn.2018-06.com.example:storage1/tpg1/portals create 172.25.254.247 //端口打开到服务器的ip Using default IP port 3260 Created network portal 172.25.254.247:3260. /> ls //查看内容 o- / .................................................................... [...] o- backstores ......................................................... [...] | o- block ............................................. [Storage Objects: 1] | | o- westos:storage1 ............ [/dev/vdb1 (2.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.2018-06.com.example:storage1 ............................. [TPGs: 1] | o- tpg1 .......................................... [no-gen-acls, no-auth] | o- acls ..................................................... [ACLs: 1] | | o- iqn.2018-06.com.example:westoskey ............... [Mapped LUNs: 1] | | o- mapped_lun0 .................. [lun0 block/westos:storage1 (rw)] | o- luns ..................................................... [LUNs: 1] | | o- lun0 ......................... [block/westos:storage1 (/dev/vdb1)] | o- portals ............................................... [Portals: 1] | o- 172.25.254.214:3260 ......................................... [OK] o- loopback .................................................... [Targets: 0] /> exit //退出 Global pref auto_save_on_exit=true Last 10 configs saved in /etc/target/backup. Configuration saved to /etc/target/saveconfig.json

注意:/iscsi/iqn.2018-06.com.example:storage1/tpg1/portals/ delete ip ip_port //删除操作




客户端设置

客户端: [root@client ~]# yum install iscsi-initiator-utils.x86_64 -y  [root@client ~]# vim /etc/iscsi/initiatorname.iscsi //编辑认证文件; InitiatorName=iqn.2018-06.com.example:westoskey //编辑内容,加密字符是服务端设定的 [root@client ~]# iscsiadm -m discovery -t st -p 172.25.254.247 //发现设备  172.25.254.247:3260,1 iqn.2018-06.com.example:storage1 [root@client ~]# iscsiadm -m node -T iqn.2018-06.com.example:storage1 -p 172.25.254.247 -l //登陆发现设备;-t 网络设备的类型,-T 网络设备名称,-l 登陆 [root@client ~]# fdisk -l //查看分区是否出现 Disk /dev/sda: 2477 MB, 2477483648 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




设备使用以及开机自动挂载

//客户端: [root@client ~]# fdisk /dev/sda //新建分区sda1 [root@client ~]# partprobe //刷新 [root@client ~]# mkfs.xfs /dev/sda1 //格式化 [root@client ~]# mount /dev/sda1 /mnt //挂载 [root@client ~]# vim /etc/fstab //编辑文件 /dev/sda1 /mnt xfs defaults,_netdev 0 0 //先启动网络服务,再去读取文件;0 0 不备份,不检测; 第一次需要手动关闭虚拟机,再挂载设备; [root@client ~]# mount -a [root@client ~]# df




设备的删除

[root@client ~]# yum install tree -y //安装树; [root@client ~]# umount /mnt //解挂  [root@client ~]# vim /etc/fstab //注释掉自动挂载的命令; [root@client ~]# iscsiadm -m node -T iqn.2018-06.com.example:storage1 -p 172.25.254.247 -u //登出设备;其中, -u是登出,跟-l相对; [root@client ~]# iscsiadm -m node -T iqn.2018-06.com.example:storage1 -p 172.25.254.247 -o delete //删除文件(如果只登出设备,不删除文件,systemctl restart iscsi 重启服务后,fidk -l设备还是存在;删除文件后,再重启设备文件都不会恢复) [root@client ~]# systemctl restart iscsi //重启服务 [root@client ~]# tree /var/lib/iscsi/ //查看树 /var/lib/iscsi/ |-- ifaces |-- isns |-- nodes |-- send_targets | `-- 172.25.254.247,3260 | `-- st_config |-- slp `-- static

原文链接:https://www.centoschina.cn/course/install/10795.html
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章