iscsi 概念
SCSI(Internet SCSI)支持从客户端(发起端)通过 IP 向远程服务器上的 iSCSI 存储设备(目标)发送 SCSI 命会。iSCSI 网定名称用于确定发起站和目标,并采用iqn.yyyy-mm.{reverse domain)}:label 的格式
默认情况下,网络通信是至 iSCSI 目标上的端口 3260/tcp 的明文端口
iscsi共享资源
建立iscsi磁盘共享,需要服务端提供储存设备,客户端获取远程服务端的存储资源达到共享,下面就是iscsi共享的服务端和客户端的相关配置
服务端:
[root@server ~]# yum install targetcli -y #安装共享策略编辑器
[root@server ~]# systemctl start target
[root@server ~]# fdisk /dev/vdb #创建分区
[root@server ~]# partprobe #同步分区
[root@server ~]# 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 test:storage1 /dev/vdb1 #修改分区名称,格式:名字 分区
Created block storage object test:storage1 using /dev/vdb1.
/> /iscsi create iqn.2018-06.com.example:storage1 #创建iscsi限定名称,iqn的方式是域名反写
Created target iqn.2018-06.com.example:storage1.
Created TPG 1.
/> ls
o- / .................................................................... [...]
o- backstores ......................................................... [...]
| o- block ............................................. [Storage Objects: 1]
| | o- test:storage1 ............ [/dev/vdb1 (2.0GiB) write-thru deactivated]
| 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: 0]
| o- luns ..................................................... [LUNs: 0]
| o- portals ............................................... [Portals: 0]
o- loopback .................................................... [Targets: 0]
/> /iscsi/iqn.2018-06.com.example:storage1/tpg1/acls create iqn.2018-06.com.example:testkey #做key,也就是加密
Created Node ACL for iqn.2018-06.com.example:testkey
/> /iscsi/iqn.2018-06.com.example:storage1/tpg1/luns create /backstores/block/test:storage1 #关联设备,也就是创建一个连接将共享与分区关联起来
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2018-06.com.example:testkey
/> /iscsi/iqn.2018-06.com.example:storage1/tpg1/portals create 172.25.254.196 #端口打开到服务器ip
Using default IP port 3260
Created network portal 172.25.254.196:3260.
/> exit #退出
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[root@server ~]# systemctl stop firewalld #关闭防火墙
客户端:
[root@client ~]# yum install iscsi-initiator-utils.x86_64 -y #安装iscsi服务
[root@client ~]# cd /etc/iscsi
[root@client iscsi]# ls
initiatorname.iscsi iscsid.conf
[root@client iscsi]# vim initiatorname.iscsi #编写配置文件
InitiatorName=iqn.2018-06.com.example:testkey #文件编辑内容,等号左边做钥匙时的所要生成的钥匙
[root@client iscsi]# systemctl restart iscsid.service
[root@client iscsi]# iscsiadm -m discovery -t st -p 172.25.254.196
#发现设备,m并表示动作,t表示网络设备类型,p指定端口
172.25.254.196:3260,1 iqn.2018-06.com.example:storage1
[root@client iscsi]# iscsiadm -m node -T iqn.2018-06.com.example:storage1 -p 172.25.254.196 -l
#登录发现的设备,T表示网络设备名称,l表示登录
Logging in to [iface: default, target: iqn.2018-06.com.example:storage1, portal: 172.25.254.196,3260] (multiple)
Login to [iface: default, target: iqn.2018-06.com.example:storage1, portal: 172.25.254.196,3260] successful.
[root@client iscsi]# fdisk -l #可以查看到iscsi的共享访问存储,下面的存储我只复制了共享存储部分的内容显示
Disk /dev/sda: 2147 MB, 2147483648 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 #建立分区
[root@client ~]# partprobe #同部分区
[root@client ~]# fdisk -l
Disk /dev/sda: 2147 MB, 2147483648 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
Disk label type: dos
Disk identifier: 0xb2b6b947
Device Boot Start End Blocks Id System
/dev/sda1 8192 4194303 2093056 83 Linux
[root@client ~]# mkfs.xfs /dev/sda1 #格式化分区
[root@client ~]# mount /dev/sda1 /mnt #格式化之后即可挂载
[root@client ~]# df #查看挂载
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3187256 7286644 31% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 80 484852 1% /dev/shm
tmpfs 484932 12788 472144 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup
/dev/mapper/vg0-vo 483670 2355 451824 1% /home
/dev/sda1 2082816 33056 2049760 2% /mnt
[root@client ~]# umount /mnt
[root@client ~]# vim /etc/fstab
文件内容如下:
_netdev表示开机加载时先激活网络再进行挂载,以免影响系统启动,当没有写_netdev时,重启系统以修改密码方式进入编辑页面,对/etc/fstab进行编辑然后退出重启即可
[root@client ~]# reboot
[kiosk@foundation69 Desktop]$ rht-vmctl view desktop
[kiosk@foundation69 Desktop]$ rht-vmctl poweroff desktop #第一次启动时先停止再启动
Powering off desktop..
[kiosk@foundation69 Desktop]$ rht-vmctl start desktop
Starting desktop.
[kiosk@foundation69 Desktop]$ rht-vmctl view desktop
[root@client ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3187056 7286844 31% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 80 484852 1% /dev/shm
tmpfs 484932 12780 472152 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup
/dev/mapper/vg0-vo 483670 2355 451824 1% /home
//172.25.254.196/student 10473900 3173760 7300140 31% /mnt
卸载删除设备
1、下载tree
2、卸载
3、注释挂载文件内容
4、退出登录
5、删除记录
[root@client ~]# yum install tree -y #安装树
[root@client ~]# tree /var/lib/iscsi/ #查看树
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
│ └── iqn.2018-06.com.example:storage1
│ └── 172.25.254.196,3260,1
│ └── default
├── send_targets
│ └── 172.25.254.196,3260
│ ├── iqn.2018-06.com.example:storage1,172.25.254.196,3260,1,default -> /var/lib/iscsi/nodes/iqn.2018-06.com.example:storage1/172.25.254.196,3260,1
│ └── st_config
├── slp
└── static
10 directories, 2 files
[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.196 -u #退出登录,-u表示登出
[root@client ~]# iscsiadm -m node -T iqn.2018-06.com.example:storage1 -p 172.25.254.196 -o delete #删除文件,可以防止在重启服务后设备依然存在。
[root@client ~]# systemctl restart iscsi #重启服务
[root@client ~]# fdisk -l #查看设备已不存在,这时候树里面记录的内容也没有了