在 Debian 上部署 Incus

IsayIsee Lv3

安装 Incus

1
2
3
4
sudo apt update

# 完整安装(支持容器 + 虚拟机)
sudo apt install -y incus

存储后端有多种可以选择,因需要使用快照等功能选择 ZFS loop:

1
2
3
4
5
6
# zfs 需要安装 linux-headers
sudo apt install linux-headers-6.12.74+deb13+1-amd64
# 安装 zfs 需要更新 source.list 添加 contrib non-free
sudo apt install -y zfsutils-linux # ZFS
# sudo apt install -y btrfs-progs # Btrfs
# sudo apt install -y lvm2 thin-provisioning-tools # LVM

三种存储方式对比

方式 需要额外硬盘 说明
dir(默认) 直接用目录存文件,最简单,无快照/克隆加速
ZFS loop 文件 自动创建 .img 文件,支持快照、克隆,推荐个人/测试用
ZFS 裸设备 性能最佳,生产环境推荐,需要一块独立磁盘或分区
Btrfs 类似 ZFS loop,也支持快照
LVM ❌/✅ 可用 loop,也可用裸设备

添加用户到 incus-admin 组

1
2
3
4
sudo usermod -aG incus-admin $USER

# 使组变更立即生效(无需重新登录)
newgrp incus-admin

初始化 Incus

1
sudo incus admin init

交互式问答,按需回答(括号内是默认值,直接回车接受):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Would you like to use clustering? (yes/no) [default=no]:
Do you want to configure a new storage pool? (yes/no) [default=yes]:
Name of the new storage pool [default=default]:
Name of the storage backend to use (dir, zfs) [default=zfs]:
Create a new ZFS pool? (yes/no) [default=yes]:
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]:
Size in GiB of the new loop device (1GiB minimum) [default=11GiB]: 30GiB
Would you like to create a new local network bridge? (yes/no) [default=yes]:
What should the new bridge be called? [default=incusbr0]:
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: none
Would you like the server to be available over the network? (yes/no) [default=no]: yes
Address to bind to (not including port) [default=all]:
Port to bind to [default=8443]:
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]:
Would you like a YAML "init" preseed to be printed? (yes/no) [default=no]:

添加国内镜像源

使用清华大学镜像时发现更新日期与实际文件不符,导致无法拉取最新镜像,改用南京大学镜像

1
2
3
4
5
6
7
# 添加南京大学镜像站
incus remote add nju \
https://mirrors.nju.edu.cn/lxc-images/ \
--protocol=simplestreams --public

# 验证
incus image list nju:

安装并启动第一个容器

部署第一个容器 Docker Host

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 从南京大学源拉取 Debian 13 容器
incus launch nju:debian/13 docker-host

# 停止容器
incus stop docker-host

# 开启嵌套虚拟化配置(这会启用必要的内核模块和安全限制放宽):
incus config set docker-host security.nesting true

incus start docker-host

# 映射端口,后期计划使用 Nginx 反向代理 Stream,使用 proxy 映射与 ufw 冲突
incus config device add docker-host portainer proxy listen=tcp:0.0.0.0:9443 connect=tcp:127.0.0.1:9443

#指定 DNS:
incus config set docker-host raw.lxc "lxc.network.dns.override=8.8.8.8,1.1.1.1"

#设置容器开机自启
incus config set docker-host boot.autostart true
# 设置延迟 10 秒启动
incus config set docker-host boot.autostart.delay 10
# 设置启动顺序(数字越小越先启动)
incus config set docker-host boot.autostart.priority 10

# 查看状态
incus list

#显示配置
incus config show docker-host

# 进入容器
incus exec docker-host -- bash

# 修改 APT 源为南京大学镜像
apt install apt-transport-https ca-certificates

vi /etc/apt/sources.list

deb https://mirror.nju.edu.cn/debian/ trixie main contrib non-free non-free-firmware
deb-src https://mirror.nju.edu.cn/debian/ trixie main contrib non-free non-free-firmware

deb https://mirror.nju.edu.cn/debian/ trixie-updates main contrib non-free non-free-firmware
deb-src https://mirror.nju.edu.cn/debian/ trixie-updates main contrib non-free non-free-firmware

deb https://mirror.nju.edu.cn/debian/ trixie-backports main contrib non-free non-free-firmware
deb-src https://mirror.nju.edu.cn/debian/ trixie-backports main contrib non-free non-free-firmware

# 以下安全更新软件源为官方源配置
deb https://security.debian.org/debian-security trixie-security main contrib non-free non-free-firmware
deb-src https://security.debian.org/debian-security trixie-security main contrib non-free non-free-firmware


# 退出容器
exit

常用发行版镜像名称:

系统 镜像名
Debian 12 tuna:debian/12
Debian 13 tuna:debian/13
Ubuntu 24.04 tuna:ubuntu/24.04
Alpine tuna:alpine/3.19
CentOS Stream 9 tuna:centos/9-Stream

常用命令速查

1
2
3
4
5
6
7
8
9
incus list                          # 列出所有容器
incus launch nju:debian/13 <名> # 创建并启动容器
incus start/stop/restart <名> # 启动/停止/重启
incus exec <名> -- bash # 进入容器 shell
incus shell <名> # 同上,更简洁
incus delete <名> # 删除容器
incus snapshot <名> <快照名> # 创建快照
incus info <名> # 查看容器详情
incus config show <名> # 查看容器配置

开机自启

Incus 守护进程在 Linux 上运行,安装后 systemd 服务会自动启用,默认开机启动。如果需要检查服务状态或启用/禁用开机启动,可以使用以下命令:

1
2
sudo systemctl status incus
sudo systemctl is-enabled incus

后期调整计划

  • 准备一块独立硬盘给 ZFS,性能和稳定性更好
  • loop 文件后续如果不够用,也可以扩容:
1
2
3
4
5
# 查看当前存储池
incus storage list

# 扩容(例如扩到 50GiB)
incus storage set default size=50GiB

防火墙

如果服务器启用了防火墙,需要进行如下调整,否则容器运行会有问题:

1
2
3
4
5
6
7
8
# 允许 router, 因为 Incus 的默认网络桥接会使用路由转发流量
sudo ufw default allow routed

# 允许 DHCP, 因为 Incus 的默认网络桥接会使用 DHCP 分配 IP 地址
sudo ufw allow in on incusbr0 to any port 67 proto udp

# 允许 DNS, 因为 Incus 的默认网络桥接会使用 DNS 解析容器域名
sudo ufw allow in on incusbr0 to any port 53 proto udp
  • 标题: 在 Debian 上部署 Incus
  • 作者: IsayIsee
  • 创建于 : 2026-04-20 15:21:23
  • 更新于 : 2026-05-18 14:00:26
  • 链接: https://blog.120528.xyz/2026/04/20/45b501a1/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论