跳至内容

1 安装与配置

在本章中,您必须以 root 用户身份操作,或者能够通过 sudo 获取 root 权限。

安装 EPEL 和 OpenZFS 仓库

Incus 需要 EPEL (Extra Packages for Enterprise Linux) 仓库,使用以下命令即可轻松安装:

dnf install epel-release -y

安装完成后,请验证没有更新

dnf upgrade

如果在升级过程中有内核更新,请重新启动服务器。

OpenZFS 仓库

使用以下命令安装 OpenZFS 仓库:

dnf install https://zfsonlinux.org/epel/zfs-release-2-8$(rpm --eval "%{dist}").noarch.rpm

安装 dkms, vim, 和 kernel-devel

安装一些必需的软件包

dnf install dkms vim kernel-devel bash-completion

安装 Incus

您需要 CRB 仓库来获取一些特殊的软件包,以及 Neil Hanlon 的 COPR (Cool Other Package Repo)

dnf config-manager --enable crb
dnf copr enable neil/incus
dnf install incus incus-tools

启用并启动服务

systemctl enable incus --now

请在继续之前重新启动服务器。

安装 OpenZFS

dnf install zfs

环境设置

要运行许多容器,所需的服务器内核设置比大多数情况要多。如果您从一开始就假设将服务器用于生产环境,那么您需要提前进行这些更改,以避免出现诸如“Too many open files”(打开文件过多)之类的错误。

幸运的是,通过对几个文件进行修改并重启服务器,就可以轻松地调整 Incus 的设置。

修改 limits.conf

您必须更改的第一个文件是 limits.conf 文件。这个文件是自文档化的。请查看文件中的注释说明,以了解这个文件做什么。要进行修改,请输入:

vi /etc/security/limits.conf

整个文件由注释组成,在文件底部显示了当前的默认设置。您需要将自定义设置添加到文件末尾标记(#End of file)上方的空白处。完成后,文件末尾将如下所示:

# Modifications made for LXD

*               soft    nofile           1048576
*               hard    nofile           1048576
root            soft    nofile           1048576
root            hard    nofile           1048576
*               soft    memlock          unlimited
*               hard    memlock          unlimited

保存更改并退出(对于 vi,请按 Shift+:+w+q+!)。

使用 90-incus-override.conf 修改 sysctl.conf

通过 systemd,您可以在修改主配置文件的情况下更改系统的整体配置和内核选项。而是将设置放在一个单独的文件中,该文件将覆盖您需要的特定设置。

要进行这些内核更改,您需要在 /etc/sysctl.d 中创建一个名为 90-incus-override.conf 的文件。要做到这一点,请输入以下命令:

vi /etc/sysctl.d/90-incus-override.conf

将以下内容放入该文件中。请注意,如果您不确定其作用,文件内容是自文档化的。

## The following changes have been made for LXD ##

# fs.inotify.max_queued_events specifies an upper limit on the number of events that can be queued to the corresponding inotify instance
 - (default is 16384)

fs.inotify.max_queued_events = 1048576

# fs.inotify.max_user_instances This specifies an upper limit on the number of inotify instances that can be created per real user ID -
(default value is 128)

fs.inotify.max_user_instances = 1048576

# fs.inotify.max_user_watches specifies an upper limit on the number of watches that can be created per real user ID - (default is 8192)

fs.inotify.max_user_watches = 1048576

# vm.max_map_count contains the maximum number of memory map areas a process may have. Memory map areas are used as a side-effect of cal
ling malloc, directly by mmap and mprotect, and also when loading shared libraries - (default is 65530)

vm.max_map_count = 262144

# kernel.dmesg_restrict denies container access to the messages in the kernel ring buffer. Please note that this also will deny access t
o non-root users on the host system - (default is 0)

kernel.dmesg_restrict = 1

# This is the maximum number of entries in ARP table (IPv4). You should increase this if you create over 1024 containers.

net.ipv4.neigh.default.gc_thresh3 = 8192

# This is the maximum number of entries in ARP table (IPv6). You should increase this if you plan to create over 1024 containers.Not nee
ded if not using IPv6, but...

net.ipv6.neigh.default.gc_thresh3 = 8192

# This is a limit on the size of eBPF JIT allocations which is usually set to PAGE_SIZE * 40000. Set this to 1000000000 if you are running Rocky Linux 9.x

net.core.bpf_jit_limit = 1000000000

# This is the maximum number of keys a non-root user can use, should be higher than the number of containers

kernel.keys.maxkeys = 2000

# This is the maximum size of the keyring non-root users can use

kernel.keys.maxbytes = 2000000

# This is the maximum number of concurrent async I/O operations. You might need to increase it further if you have a lot of workloads th
at use the AIO subsystem (e.g. MySQL)

fs.aio-max-nr = 524288

保存更改并退出。

此时,请重新启动服务器。

检查 sysctl.conf

重启后,请以 root 用户身份重新登录到服务器。您需要检查我们的覆盖文件是否已成功完成任务。

这并不难。除非您想验证所有设置,否则无需一一验证,但检查几个设置可以验证更改是否已生效。使用 sysctl 命令进行操作:

sysctl net.core.bpf_jit_limit

这将显示:

net.core.bpf_jit_limit = 1000000000 

对覆盖文件中的其他几个设置执行相同的操作,以验证更改。

作者:Steven Spencer

贡献者:Ezequiel Bruni, Ganna Zhyrnova