QEMU后端存储设置之ISCSI后端

本文详述了在Debian系统中安装与配置iSCSI Target的步骤,包括安装必需软件、设置服务启动、创建LVM分区、发布存储给客户端等关键操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文主要介绍如何在Debian中安装iscsi-target,过程主要分三步,安装服务并启动,创建存储块,最后发布给客户端。

1.1 set up iscsi-target

 

1.1.1 Install essential softwares

sudo apt-get install iscsitarget iscsitarget-dkms

iscsitarget & iscsitarget-dkms, the main packages to support iscsi service.

1.1.2 Start up iscsi-target service

- change /etc/default/iscsitarget

ISCSITARGET_ENABLE=true

- reboot iscsitarget service

sudo service iscsitarget restart

- set iscsitarget service as an auto-boot service

sudo update-rc.d iscsitarget enable 

- disable auto-boot if you want:

sudo update-rc.d iscsitarget disable

1.2 Create new volumes for iscsi-target

Iscsi-target could use different type volumes, like Image file, real disk partition, LVM partition and RAID partition. Here I am using the LVM partition since it is more flexible comparing with other types.

1.2.1 LVM

To use LVM, we will need an volume group first, it's based on physical volume. Then we could create the logical volume from volume group, and the logical volume will be used by iscsi-target.

- Sometimes, you installed the OS with a LVM support, then you could get a volume group at the boot time, and the logical volume is what you only need.

sudo lvcreate -L <size> -n <logical volume name> <volume group name>

- Sometimes, you installed the OS on physical driver, that's fine, below is what you need do.

sudo apt-get install lvm2 // install lvm first
sudo pvcreate <physical partition>  // make sure you have a separate partition
sudo vgcreate <volume group name> <physical partition>  // create the volume group based on physical partition 
sudo lvcreate -L <size> -n <logical volume name> <volume group name>  

1.2.2 Real Partition

You could use /dev/sda* or /dev/hda* directily.

1.2.3 Image file

dd if=/dev/zero of=test.img bs=1M count=1000

This will create a image file with size 1G, or you could change to the size you want.

1.3 Export new volume to client

- modify the configuration file for iscsi-target

vim /etc/iet/ietd.conf

- add configuration for new volume

Target <initiator-address> #iqn address for initiator
Lun <lun-number> Path=<path-to-volume>,Type=<volume-type> #volume information, local image file and partition use fileio and LVM or RAID volume use blockio.
initiator-address <initiator-ip-address> #initiator ip address
incominguser <target-user>  <target-password>   # authentication

Below is an example:

Target iqn.2015-12.hlinux.server:target0 
Lun 0 Path=/dev/hLinux-vg/iscsi-001,Type=blockio 
initiator-address 15.244.209.199 
incominguser hlinux secrete 

- restart iscsi-target service

sudo service iscsitarget restart
在搭建 Xen 与 QEMU 集成的虚拟化环境时,需要从内核模块加载、QEMU 编译配置、Xen 的安装与配置等多个层面进行操作。以下是详细的步骤和配置指南: ### 安装 Xen 并配置内核 1. **安装 Xen Hypervisor** 在大多数 Linux 发行版中,可以通过包管理器安装 Xen。例如,在基于 Debian/Ubuntu 的系统上使用以下命令: ```bash sudo apt install xen-hypervisor-amd64 qemu-system-x86 qemu-kvm ``` 在安装完成后,系统将自动添加 Xen 内核作为默认启动项。 2. **修改 GRUB 启动配置** 确保 GRUB 配置文件(如 `/etc/default/grub`)中的 `GRUB_CMDLINE_LINUX` 包含以下内容以启用 Xen: ```bash GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8" ``` 然后更新 GRUB: ```bash sudo update-grub ``` 3. **加载 Xen 内核模块** 系统重启后应自动进入 Xen 内核。确认当前运行的内核是否为 Xen Hypervisor: ```bash uname -r | grep xen ``` ### 编译与配置 QEMU 以支持 Xen 1. **获取 QEMU 源码并切换到兼容分支** 推荐使用官方 Git 仓库克隆源码,并选择与 Xen 兼容的版本: ```bash git clone https://git.qemu.org/git/qemu.git cd qemu git checkout stable-5.0 # 或其他稳定版本分支 ``` 2. **配置 QEMU 支持 Xen 后端** 执行 `./configure` 时需指定 Xen 支持选项: ```bash ./configure --target-list=x86_64-softmmu --enable-xen --enable-vnc --enable-debug --enable-kvm ``` 此配置启用了 Xen 支持、KVM 加速、VNC 显示以及调试功能,适用于大多数 Xen 虚拟化场景 [^1]。 3. **编译并安装 QEMU** 使用多线程加速编译过程: ```bash make -j$(nproc) sudo make install ``` ### 配置 Xen Domain 0 与 Guest 1. **创建 Xen Guest 配置文件** 创建一个 `.cfg` 文件用于定义虚拟机参数,例如 `guest.cfg`: ```ini name = "my-guest" memory = 2048 vcpus = 2 disk = [ 'file:/path/to/disk.img,xvda,w' ] vif = [ '' ] on_poweroff = 'destroy' on_reboot = 'restart' on_crash = 'restart' device_model_version = "qemu-xen-traditional" ``` 该配置指定了内存大小、磁盘映像路径及使用的 QEMU 模型版本 [^2]。 2. **启动 Xen Guest 实例** 使用 `xl` 工具启动虚拟机: ```bash sudo xl create guest.cfg sudo xl console my-guest ``` ### 网络与存储配置优化 1. **网络桥接设置** 在 Xen 中推荐使用桥接模式实现网络直通。编辑 `/etc/network/interfaces` 文件: ```bash auto br0 iface br0 inet dhcp bridge_ports eth0 bridge_stp off bridge_fd 0 bridge_maxwait 0 ``` 然后重启网络服务以应用更改。 2. **使用共享存储** 可通过 NFS 或 iSCSI 将远程存储挂载至 Xen 主机,并将其分配给多个虚拟机实例,提升资源利用率。 ### 监控与管理工具集成 1. **集成 Libvirt 管理 Xen** 安装并配置 libvirt 以统一管理 Xen 和 QEMU: ```bash sudo apt install libvirt-daemon-system sudo virsh -c xen:/// list ``` 这将列出所有 Xen 虚拟机,便于集中管理 [^3]。 2. **使用 virt-manager 图形界面** 安装 `virt-manager` 后可通过图形界面远程连接 Xen Hypervisor,简化虚拟机部署流程。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

认真的柯南

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值