OpenEuler24.03 SP4安装Rancher时遇到cgroupv2和iptables问题的经验

OpenEuler(欧拉)是由开放原子开源基金会孵化的全场景通用开源操作系统项目, Rancher 是 SUSE 公司的开源 Kubernetes 容器云管理平台。

之前在阿里云的 OpenAnolis 和Oracle云的 RockyLinux 上安装时,核心只需要解决镜像下载问题即可,但是在 OpenEuler 上遇到了 cgroup驱动问题iptables内核模块缺失问题 ,本文详细介绍异常日志现场以及解决方法。

之前的问题可以参考文章:

cgroup驱动问题

cgroup v2 是 Linux 内核的一项功能,用来限制、隔离和统计进程组的资源使用(如 CPU、内存、磁盘 I/O 等)。

Kubernetes 运行依赖 Linux 内核的 CgroupV2 驱动。Rancher 的 Docker 部署方案中默认会在容器中运行 Kubernetes 集群(k3s),所以如果 Linux 系统不是 CgroupV2 时,Rancher 无法正常启动。

在 k3s.log 中有 error 异常日志:

bash 复制代码
time="2026-08-27T14:03:15+08:00" level=error msg="Shutdown request received: \
"kubelet exited: failed to validate kubelet configuration, error: 
kubelet is configured to not run on a host using cgroup v1. 
cgroup v1 support is unsupported and will be removed in a future release, 
path: &TypeMeta{Kind:,APIVersion:,}\""

这里核心的错误提示不支持 cgroup v1 :kubelet is configured to not run on a host using cgroup v1

查看当前挂载的cgroup类型

查看当前系统是否时 CgroupV2 可以通过 stat 命令来检查确认

bash 复制代码
# stat -fc %T /sys/fs/cgroup/
tmpfs

OpenEuler 安装后默认的是 tmpfs,即默认没有使用 Cgroup V2。

  • 输出 tmpfs:表示系统正在使用 cgroup v1。
  • 输出 cgroup2fs:表示系统正在使用 cgroup v2。

CgroupV2 在 Linux 4.5 版本就支持了。OpenEuler的两个主流版本中,OpenEuler 22.03 LTS 默认内核是 5.10.x ,openEuler 24.03 LTS 默认是 6.6.x,所以内核层面都是支持,只是默认没有使用。

解决 OpenEuler 支持 Cgroup V2 的方法是在内核启动参数上添加配置: systemd.unified_cgroup_hierarchy=1

修改步骤:

  • 步骤一:添加内核配置

注意:是添加到引号内的参数后面,不是替换整行

建议在修改前先备份grub文件 cp /etc/default/grub /etc/default/grub.bak

bash 复制代码
sed -i 's/GRUB_CMDLINE_LINUX="/GRUB_CMDLINE_LINUX="systemd.unified_cgroup_hierarchy=1 /' /etc/default/grub

修改后的 GRUB_CMDLINE_LINUX 配置参考:

bash 复制代码
[root@localhost ~]# cat /etc/default/grub |grep GRUB_CMDLINE_LINUX
GRUB_CMDLINE_LINUX="systemd.unified_cgroup_hierarchy=1 resume=/dev/mapper/openeuler-swap rd.lvm.lv=openeuler/root rd.lvm.lv=openeuler/swap cgroup_disable=files apparmor=0 crashkernel=512M"
  • 步骤二:重新生成grub配置

然后需要重新生成 grub 配置

bash 复制代码
grub2-mkconfig -o /boot/grub2/grub.cfg
  • 步骤三:重启系统

在生成新的 grub 配置后,还需 reboot 重启机器,否则内核无法识别新配置。

然后在确认 CgroupV2 支持情况:

bash 复制代码
[root@localhost ~]#  stat -fc %T /sys/fs/cgroup/
cgroup2fs

输出 cgroup2fs 说明修改成功。

然后就可以重启 rancher 检查状态和日志。

iptables 内核模块缺失

重启后新的 error 异常 kube-proxy exited: iptables is not available on this host 提示 kube-proxy 无法运行。容器网络无法正常工作,集群也就无法正常启动。

bash 复制代码
time="2026-08-27T14:29:18+08:00" level=error msg="Shutdown request received: \
"kube-proxy exited: iptables is not available on this host : 
error listing chain \\\"POSTROUTING\\\" in table \\\"nat\\\": exit status 3: 
iptables v1.8.11 (legacy): can't initialize iptables table `nat':
Table does not exist (do you need to insmod?)\\n
Perhaps iptables or your kernel needs to be upgraded.\\n\""

并且在启动的最开始就有 warning 异常提示加载内核失败

bash 复制代码
time="2026-08-27T14:29:07+08:00" level=warning msg="Failed to load kernel module iptable_nat with modprobe"
time="2026-08-27T14:29:07+08:00" level=warning msg="Failed to load kernel module iptable_filter with modprobe"
time="2026-08-27T14:29:07+08:00" level=warning msg="Failed to load kernel module nft-expr-counter with modprobe"
time="2026-08-27T14:29:07+08:00" level=warning msg="Failed to load kernel module nfnetlink-subsys-11 with modprobe"
time="2026-08-27T14:29:07+08:00" level=warning msg="Failed to load kernel module nft-chain-2-nat with modprobe"

这是因为 OpenEuler 默认的防火墙是 firewalld 服务底层使用的是 nftables 而不是 iptables

kube-proxy 也支持 nftables,但是在 Rancher 单机 Docker 方案在部署过程不方便修改配置,需要启用内核的 iptables 模块

以下是 iptables 的核心内核模块,默认 OpenEueler24 SP4 都没有加载

  • br_netfilter - 网络桥接过滤
  • iptable_nat - NAT 表支持
  • iptable_filter - 过滤表支持
  • ip_tables - 核心 iptables 支持

加载内核模块

bash 复制代码
modprobe br_netfilter
modprobe iptable_nat
modprobe iptable_filter
modprobe ip_tables

内核加载完成后,可以检查下

bash 复制代码
[root@localhost ~]# lsmod |grep -E "^(br_netfilter|iptable_nat|iptable_filter|ip_tables)"
iptable_filter         12288  0
iptable_nat            12288  0
ip_tables              36864  2 iptable_filter,iptable_nat
br_netfilter           36864  0

然后再重启 Rancher 的容器,就可以正常启动了

但是,这种 modprobe 的方法在重启后会失效,可以通过开机启动加载,比如放在 /etc/profile 中。也可以在 /etc/modules-load.d/ 目录中创建文件如 iptables.conf,该文件在开机启动 systemd 服务时也会自动加载。

bash 复制代码
cat > /etc/modules-load.d/iptables.conf << EOF
iptable_nat
iptable_filter
ip_tables
br_netfilter
EOF

总结

OpenEuler 是 CentOS 的一种替代,其选择基于更新的 Linux Kernel 在云原生场景下具有很好的优势,但在考虑到历史场景的兼容性时做了一些妥协,不过这些功能上的开关对操作系统类型的选择影响很小,一般的技术人员根据操作步骤都可以解决,最困难的点可能就是一开始如何发现问题,本文提供问题现场的具体日志,在遇到相同问题时可以快速的确认和解决。

相关推荐
赵文宇(温玉)10 天前
OpenEuler24.03 SP4 系统安装(欧拉/麒麟V10)
linux·openeuler·欧拉
snow@li1 个月前
SpringBoot:项目基于Rancher全景梳理与深入分析/Kubernetes可视化管理平台
rancher
神秘剑客_CN1 个月前
openEuler 22.03安装openGauss 6.0
linux·opengauss·openeuler
Kina_C2 个月前
Linux iptables 防火墙原理与实操——从四表五链到 NAT 配置
linux·运维·服务器·iptables
Junsir大斗师2 个月前
keepalived实现ubuntu22服务器高可用
运维·ubuntu·iptables·keepalived·二层透明网桥
wangyadong3173 个月前
rancher 安装jenkins 。国内镜像太头疼
servlet·jenkins·rancher
wangyadong3173 个月前
重新安装k3s,因为我安装jenkins 的时候报错了。不知道为啥rancher 访问不了了。
linux·服务器·rancher
宋冠巡3 个月前
OpenEuler 系统下 Nginx 安装配置与管理指南(基于 OpenEuler 22.03 LTS SP4)
nginx·openeuler
qq_356408663 个月前
Rancher 安装与配置文档
rancher