第一章:安装和配置¶
在本章中,您需要以 root 用户身份操作,或者能够通过 sudo 切换到 root 用户。
安装 EPEL 和 OpenZFS 仓库¶
LXD 需要 EPEL(Extra Packages for Enterprise Linux)仓库,可以使用以下命令轻松安装:
dnf install epel-release
安装完成后,请检查是否需要更新。
dnf upgrade
如果在升级过程中有任何内核更新,请重启服务器。
OpenZFS 仓库¶
使用以下命令安装 OpenZFS 仓库:
dnf install https://zfsonlinux.org/epel/zfs-release-2-8$(rpm --eval "%{dist}").noarch.rpm
安装 snapd
, dkms
, vim
, 和 kernel-devel
¶
在 Rocky Linux 上安装 LXD 需要一个 snap 包。因此,您需要使用以下命令安装 snapd
(以及其他一些有用的程序):
dnf install snapd dkms vim kernel-devel
现在启用并启动 snapd:
systemctl enable snapd
然后运行
systemctl start snapd
请在此之前重启服务器。
安装 LXD¶
安装 LXD 需要使用 snap 命令。此时,您只是安装它,尚未进行设置。
snap install lxd
安装 OpenZFS¶
dnf install zfs
环境设置¶
大多数服务器的内核设置不足以运行大量容器。如果您一开始就打算在生产环境中使用服务器,则需要提前进行这些更改,以避免出现“文件过多”等错误。
幸运的是,通过一些文件修改和重启,调整 LXD 的设置并不难。
修改 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-lxd.override.conf
修改 sysctl.conf¶
使用 systemd,您可以在*不*修改主配置文件的情况下对系统的整体配置和内核选项进行更改。相反,将您的设置放在一个单独的文件中,该文件将覆盖您需要的特定设置。
要进行这些内核更改,您将在 /etc/sysctl.d
中创建一个名为 90-lxd-override.conf
的文件。为此,请键入:
vi /etc/sysctl.d/90-lxd-override.conf
RL 9 和 net.core.bpf_jit_limit
的最大值
由于最近的内核安全更新,net.core.bpf_jit_limit
的最大值似乎是 1000000000。如果您正在运行 Rocky Linux 9.x,请在下面的自注释文件中调整此值。如果您将其设置为高于此限制的值*或*未能设置它,它将默认为系统默认值 264241152,如果您运行大量容器,这可能不足够。
将以下内容放入该文件中。请注意,如果您对此感到困惑,文件内容本身就有注释说明。
## 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 = 3000000000
# 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 = 3000000000
对覆盖文件中的其他几个设置执行相同的操作,以验证更改。
作者:Steven Spencer
贡献者:Ezequiel Bruni, Ganna Zhyrnova