- 创建者: 虚拟的现实,上次更新时间:1月 18, 2024 需要 3 分钟阅读时间
如果机器的磁盘空间不够,可以用 iscsi 把服务器 172.18.30.18 上面划出一片空间,远程挂上来用。
注意,服务器用 losetup 的这种做法是为了将来 k8s 也可以这样用动态iscsi卷。
服务器端安装
登录172.18.30.18 安装对应的组件,用文件来虚拟 LVM 卷(20T)。
yum install -y targetcli targetd cd /glusterfs/iscsi-volumes/ dd if=/dev/zero of=k8s-iscsi-volumes.img bs=1G count=20000 export LOOP=`losetup -f` losetup $LOOP k8s-iscsi-volumes.img vgcreate vg-targetd $LOOP
修改 targetd.yaml:
vi /etc/target/targetd.yaml password: xxxxxxxx # defaults below; uncomment and edit # if using a thin pool, use <volume group name>/<thin pool name> # e.g vg-targetd/pool pool_name: vg-targetd user: admin ssl: false target_name: iqn.2020-04.com.ddky:renhe-18-30-18
注意,这个文件生成后,就不需要改动了,如果以后target_name变了,也不用管,也不需要重启targetd
启动服务:
systemctl enable --now target systemctl enable --now targetd
运行一下命令,看看显示结果 pvdisplay vgdisplay lvdisplay targetcli ls /
注意:lvdisplay 结果和 targetcli ls / 结果都是空
如果有定义好的iscsi,3260端口才会开放。所以现在只开启了 18700 的targetd,3260未开放中。
如果以后定义好了,那么显示结果如下图:
删除已经存在的iscsi卷
首先删掉block设备 targetcli /backstores/block delete vg-targetd:pvc-harbor 然后删除iscsi targetcli /iscsi delete iqn.2020-07.com.ddky:renhe-18-30-18 最后删除lv lvremove /dev/vg-targetd/pvc-harbor
释放 iscsi 卷
先删除backstores,然后是iscsi,lv,vg,pv
# targetcli /backstores/block delete vg-targetd:pvc-harbor Deleted storage object vg-targetd:pvc-harbor. # targetcli /backstores/block delete vg-targetd:pvc-vis-18-31-48 Deleted storage object vg-targetd:pvc-vis-18-31-48. # targetcli /backstores/block delete vg-targetd:pvc-vis-18-31-49 Deleted storage object vg-targetd:pvc-vis-18-31-49. # targetcli /iscsi delete iqn.2020-07.com.ddky:renhe-18-30-18 Deleted Target iqn.2020-07.com.ddky:renhe-18-30-18. # targetcli /iscsi delete iqn.2020-10.com.ddky:vis-18-31-48 Deleted Target iqn.2020-10.com.ddky:vis-18-31-48. # targetcli /iscsi delete iqn.2020-10.com.ddky:vis-18-31-49 Deleted Target iqn.2020-10.com.ddky:vis-18-31-49. # lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert pvc-harbor vg-targetd -wi-a----- 200.00g pvc-vis-18-31-48 vg-targetd -wi-a----- 80.00g pvc-vis-18-31-49 vg-targetd -wi-a----- 80.00g # lvremove /dev/vg-targetd/pvc-harbor Do you really want to remove active logical volume vg-targetd/pvc-harbor? [y/n]: y Logical volume "pvc-harbor" successfully removed # lvremove /dev/vg-targetd/pvc-vis-18-31-48 Do you really want to remove active logical volume vg-targetd/pvc-vis-18-31-48? [y/n]: y Logical volume "pvc-vis-18-31-48" successfully removed # lvremove /dev/vg-targetd/pvc-vis-18-31-49 Do you really want to remove active logical volume vg-targetd/pvc-vis-18-31-49? [y/n]: y Logical volume "pvc-vis-18-31-49" successfully removed # vgremove vg-targetd Volume group "vg-targetd" successfully removed # lvs # vgs # pvs PV VG Fmt Attr PSize PFree /dev/loop0 lvm2 --- 19.53t 19.53t # pvremove /dev/loop0 Labels on physical volume "/dev/loop0" successfully wiped.
然后清理文件,需要注意如果不停掉targetd服务,是无法remove loop设备的
systemctl stop targetd losetup -a losetup -d /dev/loop0 losetup -a cd /glusterfs/iscsi-volumes rm -f k8s-iscsi-volumes.img
建立新的卷的方法
建立新的lv pvc-harbor, 200G lvcreate -L 200G -n pvc-harbor vg-targetd 建立新的block设备 targetcli /backstores/block create vg-targetd:pvc-harbor /dev/vg-targetd/pvc-harbor 建立新的iqn targetcli /iscsi create iqn.2020-07.com.ddky:renhe-18-30-18 建立新的lun,portal会自动建立,3260端口会开放 targetcli /iscsi/iqn.2020-07.com.ddky:renhe-18-30-18/tpg1/luns create /backstores/block/vg-targetd:pvc-harbor 建立新的acls targetcli /iscsi/iqn.2020-07.com.ddky:renhe-18-30-18/tpg1/acls create iqn.2020-07.com.ddky:harbor-18-31-28 设置acls的鉴权 targetcli /iscsi/iqn.2020-07.com.ddky:renhe-18-30-18/tpg1/acls/iqn.2020-07.com.ddky:harbor-18-31-28 set attribute authentication=0 targetcli /iscsi/iqn.2020-07.com.ddky:renhe-18-30-18/tpg1/acls/iqn.2020-07.com.ddky:harbor-18-31-28 set auth userid=admin password=nishiwode 如果lun只对srv2开放,不对srv1开放,方法如下: targetcli iscsi/iqn.2003-01.local.rhce.ipa:target/tpg1/acls create iqn.1994-05.com.redhat:srv1 add_mapped_luns=false targetcli iscsi/iqn.2003-01.local.rhce.ipa:target/tpg1/acls create iqn.1994-05.com.redhat:srv2
ok,如上,服务器端就设置好了
这里没有重启,只是运行了 targetcli saveconfig 实测,真的不需要重启target,systemctl restart target
客户端安装
安装iscsi客户端
修改initiatorname.iscsi,也就是自己的iqn号
yum install iscsi-initiator-utils -y vi /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2020-07.com.ddky:harbor-18-31-28
修改iscsid.conf,并重启服务
vi /etc/iscsi/iscsid.conf,增加3行 node.session.auth.authmethod = CHAP node.session.auth.username = admin node.session.auth.password = xxxxxxxx systemctl restart iscsid
发现一下对端:
# iscsiadm -m discovery -t sendtargets -p 172.18.30.18:3260 172.18.30.18:3260,1 iqn.2020-07.com.ddky:renhe-18-30-18
登录ISCSI:
# iscsiadm -m node -T iqn.2020-07.com.ddky:renhe-18-30-18 -p 172.18.30.18:3260 --login Logging in to [iface: default, target: iqn.2020-07.com.ddky:renhe-18-30-18, portal: 172.18.30.18,3260] (multiple) Login to [iface: default, target: iqn.2020-07.com.ddky:renhe-18-30-18, portal: 172.18.30.18,3260] successful.
查看session:
iscsiadm -m session -P3 | less
系统中会多出一块盘,/dev/sda
直接格式化,不要分区,mkfs.xfs /dev/sda
查出uuid
blkid /dev/sda /dev/sda: UUID="58024012-aa03-4091-a11a-0bb74beeed5a" TYPE="xfs"
编辑/etc/fstab
vi /etc/fstab UUID=58024012-aa03-4091-a11a-0bb74beeed5a /mnt xfs _netdev 0 0
给 vis-18-31-48 增加 pxe 的 sanboot 启动硬盘的方法
#划个lvc,用的是vg-targetd的20T中的80G lvcreate -L 80G -n pvc-vis-18-31-48 vg-targetd #建立block块设备 targetcli /backstores/block create vg-targetd:pvc-vis-18-31-48 /dev/vg-targetd/pvc-vis-18-31-48 #建立30.18上的iscsi服务端,似乎用renhe-18-30-18比较好,但是不好区分多个卷 targetcli /iscsi create iqn.2020-10.com.ddky:vis-18-31-48 #建立luns,会自动建立portal targetcli /iscsi/iqn.2020-10.com.ddky:vis-18-31-48/tpg1/luns create /backstores/block/vg-targetd:pvc-vis-18-31-48 #建立客户端的iscsi,不加认证 targetcli /iscsi/iqn.2020-10.com.ddky:vis-18-31-48/tpg1/acls create iqn.2020-10.com.ddky:vis-18-31-48
这样客户端用 iqn.2020-10.com.ddky:vis-13-31-48 就可以mount出来
- 无标签
添加评论