标签归档:lxc

lxc 使用 chronyc 构建 ntp 服务

lxc 启动 chronyd 是无法直接启动的,因为用到了很多未授权的权限。

TL;DR

lxc与宿主机共用内核,因此时间也是共用的,无需同步。如果你想构建一个 ntp 服务,不需要同步时间,可以像下面这样做:

$ sudo systemctl edit chrony
# 新增以下内容:
[Service]
User=
Group=
ExecStart=
ExecStart=/usr/sbin/chronyd -F 1 -x

这些配置会覆写默认的 chrony 后台服务参数,启动 chronyd 时加 -x,禁用步进/微调系统时钟,这样即使没有 CAP_SYS_TIME 也能跑起来。 上面两行 UserGroup 这样 chronyd 会以 root 启动,然后按照 /etc/chrony/chrony.conf 里的 user chrony 自动降权运行,这是官方推荐方式。

这样配置后 chrony 的服务就可以启动了,可以对外发布 ntp 服务。

Refs

确认当前终端是否运行在 LXC 容器

要确定当前运行的系统是否在 LXC 容器中,可以检查特定的环境变量和文件。以下是一种方法,通过查看 /proc/1/environ 文件来判断:

在终端中运行以下命令:

cat /proc/1/environ | tr '\0' '\n' | grep '^container='

观察输出的内容。如果输出包含 container=lxc,则表示您当前正在 LXC 容器内运行。例如:

container=lxc

如果输出为空,那么您可能不在 LXC 容器内运行。

另一种方法是检查 /proc/1/cgroup 文件,类似于检查 Docker 容器的方法:

cat /proc/1/cgroup

观察输出的内容。如果您看到与 LXC 相关的内容(如 lxc),则表示您当前正在 LXC 容器内运行。例如:

10:memory:/lxc/1234
9:devices:/lxc/1234
...

请注意,这些方法主要适用于 LXC 容器,而不一定适用于其他容器技术(如 Docker、Podman 等)。如果您使用的是其他容器技术,可能需要查找特定于该技术的文件或环境变量。

更换 PVE7 软件仓库源和 CT模板(LXC)源为国内源

PVE7 安装后默认配置的 apt 软件源和 CT(LXC)容器模板源均是官方默认的,国内使用性能不佳,建议替换为 清华 Tuna 提供的国内镜像源,速度将有一个较大的提升。

如果 pve 官网 iso 镜像下载较慢,也可在 tuna 提供的镜像站下载:https://mirrors.tuna.tsinghua.edu.cn/proxmox/iso/

注:本文以 pve 7.0.2 (debian 11 bulleye) 为例,其他版本请自行在镜像网站寻找对应地址。

替换 apt 软件源

替换前建议先更新下证书,否则可能由于证书不可用导致 https 无法使用,进而无法下载所有软件。

$ sudo apt install apt-transport-https ca-certificates

首先替换通用软件源, Debian 的软件源配置文件是 /etc/apt/sources.list,备份后将其中内容修改为以下即可。

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free

deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free

之后替换 pve 软件源,pve 镜像默认的 pve 软件源配置文件是 /etc/apt/sources.list.d/pve-enterprise.list ,备份后将其中内容替换为以下即可:

deb https://mirrors.tuna.tsinghua.edu.cn/proxmox/debian bullseye pve-no-subscription

最后更新下,速度很快:

sudo apt-get update

修改 CT Templates (LXC容器)源

将 /usr/share/perl5/PVE/APLInfo.pm 文件中默认的源地址 http://download.proxmox.com 替换为 https://mirrors.tuna.tsinghua.edu.cn/proxmox 即可。

可以使用如下命令修改:

cp /usr/share/perl5/PVE/APLInfo.pm /usr/share/perl5/PVE/APLInfo.pm_back
sed -i 's|http://download.proxmox.com|https://mirrors.tuna.tsinghua.edu.cn/proxmox|g' /usr/share/perl5/PVE/APLInfo.pm

针对 /usr/share/perl5/PVE/APLInfo.pm 文件的修改,重启后生效。

systemctl restart pvedaemon.service

之后在 pve 网页端下载 CT Templates 速度就很快了。

参考文献