iSCSI
----------------------------------Inetnet SCSI-iSCSI(tcp3260)-----------------------------------------
targetcli 将Linux系统模拟成为iSCSI target功能iSCSI服务器
iscsi-initiator-utils 挂载来自target的硬盘到Linux本机上iSCSI客户端
服务器操作
#yum install targetcli
1. 准备磁盘
#mkdir -v /iscsihd[准备img类型的硬盘的存放目录]
2.建立iSCSI所需的四块磁盘
(1)镜像文件:disk1.img (2)独立分区:/dev/sdb1 (3)LVM: /iscsi/iscsi01 (4)disk2.img在targetcli中实现
(1)镜像文件:disk1.img
#dd if=/dev/zero of=/iscsihd/disk01.img bs=1M count=500
(2)独立分区:/dev/sdb1
#fdisk /dev/sdb
(3)LVM: /iscsi/iscsi01
#fdsik /dev/sdc
System ID改为8e(LVM)→fdisk t 8E[修改LVM类型]
#fdisk p
#pvcreate /dev/sdb2
#vgcreate –s 4M iscsi /dev/sdb2
#lvcreate –L 2G –n iscsi01 iscsi
#lvscan
进入
#targetcli
cd 进入某个目录 ls 列示某个目录 create 创建指定目标 delete 删除指定目标
exit 退出 pwd 显示当前工作目录 set 对指定的项目进行相关设定 status 查看当前状态
/> 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]
/> pwd
/
/> status
Status for /:
/> cd backstores/fileio
/backstores/fileio> ls
o- fileio ............................................................................ [Storage Objects: 0]
/backstores/fileio> create disk01 /srv/iscsi/disk01.img创建LUNS(将准备的硬盘加入至iSCSI服务中)
Created fileio disk01 with size 524288000
/backstores/fileio> create disk02 /dev/sdb1
Note: block backstore preferred for best results
Created fileio disk02 with size 4294967296
/backstores/fileio> create disk03 /dev/iscsi/iscsi01
Note: block backstore preferred for best results
Created fileio disk03 with size 4290772992
/backstores/fileio> create disk04 /iscsihd/disk04.img 2G*创建第四块硬盘,空间为2G
Created fileio disk04 with size 2147483648
/backstores/fileio> ls
o- fileio ............................................................................ [Storage Objects: 4]
o- disk01 ....................................... [/iscsihd/disk01.img (500.0MiB) write-back deactivated]
o- disk02 ................................................... [/dev/sdb1 (4.0GiB) write-back deactivated]
o- disk03 ................................................... [/dev/dm-8 (4.0GiB) write-back deactivated]
o- disk04 ......................................... [/iscsihd/disk04.img (2.0GiB) write-back deactivated]
IQN -- iSCSI Qualified Name
/backstores/fileio>cd /iscsi
/iscsi> create iqn.2016-10.edu.yht.www:yht1[*iqn的格式为iqn.年-月.FQDN倒写:iscsi存储名]
/iscsi>cd “iqn.2016-10.edu.yht.www:yht1”/tpg1/portals
/iscsi/iqn.20.../tpg1/portals> delete ip_address=0.0.0.0 ip_port=3260[删除IP及端口]→3260是默认端口
/iscsi/iqn.20.../tpg1/portals> create ip_address=192.168.131.128 ip_port=8888[指定某个IP的某个端口]
/iscsi/...portals>cd ../luns
/iscsi/iqn.20.../tpg1/luns> create /backstores/fileio/disk01配置LUNS(增加所需要的硬盘)
Created Lun 0.
/iscsi/iqn.20.../tpg1/luns> create /backstores/fileio/disk02
Created Lun 1.
/iscsi/iqn.20.../tpg1/luns> create /backstores/fileio/disk03
Created Lun 2.
/iscsi/iqn.20.../tpg1/luns> create /backstores/fileio/disk04
Created Lun 4.
/iscsi/...luns>cd ../
/iscsi/iqn.20.../tpg1/> set attribute authentication=0[关闭全局认证]
/iscsi/iqn.20.../tpg1/> set attribute generate_node_acls=1[生成节点acl]
/iscsi/...portals>cd acls
/iscsi/iqn.20.../tpg1/acls> create iqn.2016-10.edu.yht.www:www.yht.edu[创建iqn的FQDN]
Created Node ACL for iqn.2016-10.edu.yht.www:www.yht.edu
Created mapped LUN 3.
Created mapped LUN 2.
Created mapped LUN 1.
Created mapped LUN 0.
/iscsi/...acls>cd iqn.2016-10.edu.yht.www:www.yht.edu
/iscsi/iqn.20...:www.yht.edu> set auth userid=snow
Parameter userid is now 'snow'.
/iscsi/iqn.20...:www.yht.edu> set auth password=123
Parameter password is now '123'.
/iscsi/iqn.20...:www.blue.edu> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
查看服务的启动
#netstat -lnat | grep 3260
查看进行
#ps aux | grep targetcli
客户端操作
#yum install iscsi-initiator-utils
#vim /etc/iscsi/initiatorname.iscsi[配置验证区域名称及密码]
InitiatorName=ian.2016-10.edu.yht.www:www.yht.edu
#vi /etc/iscsi/iscsid.conf
将54行开启:启动CHAP认证方式
node.session.auth.authmoted = CHAP
将58行开启:写入合法的验证用户账号
node.session.auth.username = snow
将59行开启:写入合法的密码
node.session.auth.password = 123
# systemctl [ restart | enable ] iscsid[启动服务]
# iscsiadm -m discovery -t sendtargets -p 192.168.131.128:8888[查找iSCSI服务]→默认端口在此不用加端口
# ll -R /var/lib/iscsi/nodes[查询本地是否收到Server端的target]
# iscsiadm -m node -o show[找出目前本机上所有检测到的target信息]
#iscsiadm –m node -T iqn.2016-10.edu.yht.www:yht1 --login[登陆到iscsi空间]
//*如果能查看到服务器信息但登录不上,重关闭一遍全局认证和生成ACL
#lsblk[查看本地磁盘情况]
#iscsiadm -m node -T iqn.2016-10.edu.yht.www:niliustorage1 --logout[登出到iscsi空间]
#lsblk[查看本地磁盘情况]
添加/删除/更新target
#iscsiadmin -m node T iqn.2016-10.edu.yht.www:yht1 --logout
#iscsiadm -m node –o delete -T iqn.2016-10.edu.yht.www:yht1
#iscsiadm -m node
参数说明
-o delete 删除
-o update 更新
-o new 增加
#fdisk /dev/sdb
#fdisk /dev/sdc
#fdisk /dev/sdd
使用target空间生成LVM
#pvcreate /dev/sd{b,c,d,e}1
#vgcreate iscsi /dev/sd{b,c,d,e}1
#vgdiskplay
#lvcreate –L 空间大小 – n iscsi01 iscsi
#mkfs.ext4 /dev/iscsi/iscsi01
#mkdir –v /mnt/iscsi
#mount /dev/iscsi/iscsi01 /mnt/iscsi
测试
自动挂载
1)本地确定IP无问题,且自启动后可以直接联系到iSCSI服务
2)将指定的target作为自动链接
#iscsiadm -m node -T targetiqn.2016-10.edu.yht.www:yht1 -p 192.168.131.128 -o update -n node.startup -v automatic
3)修改fstab
#vim /etc/fstab
/dev/iscsi/iscsi01 /mnt/iscsi ext4 defaults,_netdev 0 0