CFEngine 3.27.2 CentOS 8 安装指南
在 CentOS 8 上从零安装 CFEngine 3.27.2 LTS 社区版:EOL 源修复排障、官方 rpm 下载校验、dnf/rpm 双方案安装、自举与 systemd 验证、升级降级与卸载全流程,含 selinux 依赖与 NOKEY 排障实录
CFEngine 3.27.2 CentOS 8 安装指南
目标:在 CentOS 8 服务器上从零安装 CFEngine 3.27.2 社区版(Community),完成 EOL 软件源修复、官方 rpm 包下载校验、dnf/rpm 双方案安装、策略自举(bootstrap)、systemd 服务验证、升级降级与彻底卸载的完整 0→1 流程。全部命令与回显均在 CentOS Linux 8(x86_64)真实环境实测通过。
一、环境信息
本文所有命令在以下环境实测通过,读者可按同样配置复现:
- 操作系统:CentOS Linux 8(x86_64,el8 平台)
- 架构:x86_64
- CFEngine 版本:3.27.2(社区版 / Community Edition,3.27.x LTS 线最新版本)
- 安装路径:
/var/cfengine/(CFEngine 全部组件与数据的工作根目录) - systemd 单元:
cfengine3.service(总控单元)+cf-serverd.service、cf-execd.service、cf-monitord.service(子服务单元) - 通信端口:TCP 5308(cf-serverd 监听,策略分发与远程执行通道)
- 用户:root
💡 说明:CFEngine 是基于「策略(policy)」声明式驱动的配置管理工具,由
cf-agent(策略执行)、cf-serverd(策略分发服务)、cf-execd(定时调度执行)三大守护进程组成;单机场景自举到本机(127.0.0.1)即可。与 Ansible/Puppet/SaltStack 等同类工具的横向对比见《CFEngine 3.27.2 Ubuntu 22.04 安装指南》第一章的技术拓展说明;社区版与 Enterprise 版差异见同文档 3.3 节。
系统版本确认:
cat /etc/os-release
uname -m
实测回显:
NAME="CentOS Linux"
VERSION="8"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
x86_64
PLATFORM_ID: platform:el8 对应官方 rpm 包名中的 el8 标签。
二、前置条件与系统源修复(CentOS 8 EOL 排障实录)
CentOS 8 已于 2021-12-31 停止维护(EOL),官方 mirrorlist.centos.org 已停止解析,因此安装任何软件(包括本文需要的 wget/dnf 依赖)之前,必须先把系统源指向归档仓库。这是 CentOS 8 上安装 CFEngine 的第一道坎,本节按「现象 → 定位 → 解决」完整实录。
2.1 现象:dnf makecache 报无法解析 mirrorlist
dnf makecache
实测回显(失败现象):
CentOS Linux 8 - AppStream 0.0 B/s | 0 B 00:55
Errors during downloading metadata for repository 'AppStream':
- Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]
Error: Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]
2.2 定位
Could not resolve host: mirrorlist.centos.org 表明镜像列表服务已下线。查看当前源配置(默认两个仓库文件):
cat /etc/yum.repos.d/CentOS-Linux-BaseOS.repo
实测回显(原始内容,还原自备份):
[BaseOS]
name=CentOS Linux 8 - BaseOS
mirrorlist=http://mirrorlist.centos.org/?release=8&arch=$basearch&repo=BaseOS&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
配置使用 mirrorlist= 动态列表,而该域名已停止解析;被注释的 baseurl= 指向的 mirror.centos.org 也只保留 8.5.2111 及之前版本的归档内容。
2.3 解决:改用归档仓库 baseurl
把两个仓库文件(BaseOS/AppStream)的 mirrorlist 注释掉、baseurl 指向归档镜像(以清华 TUNA 的 centos-vault 为例,内网可换任意可达的 vault 镜像)。先修改 BaseOS:
sed -i 's|^mirrorlist=|#mirrorlist=|; s|^#baseurl=|baseurl=|' /etc/yum.repos.d/CentOS-Linux-BaseOS.repo
sed -i 's|http://mirror.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/|https://mirrors.tuna.tsinghua.edu.cn/centos-vault/8.5.2111/BaseOS/x86_64/os/|' /etc/yum.repos.d/CentOS-Linux-BaseOS.repo
cat /etc/yum.repos.d/CentOS-Linux-BaseOS.repo
实测回显:
[BaseOS]
name=CentOS Linux 8 - BaseOS
#mirrorlist=http://mirrorlist.centos.org/?release=8&arch=$basearch&repo=BaseOS&infra=$infra
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/8.5.2111/BaseOS/x86_64/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
AppStream 同样处理(直接写入完整文件,避免 sed 漏改):
cat > /etc/yum.repos.d/CentOS-Linux-AppStream.repo <<'EOF'
[AppStream]
name=CentOS Linux 8 - AppStream
#mirrorlist=http://mirrorlist.centos.org/?release=8&arch=$basearch&repo=AppStream&infra=$infra
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/8.5.2111/AppStream/x86_64/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
验证修复生效:
dnf makecache
实测回显:
CentOS Linux 8 - AppStream 45 kB/s | 4.3 kB 00:00
CentOS Linux 8 - BaseOS 44 kB/s | 3.9 kB 00:00
Metadata cache created.
⚠️ 注意:8.5.2111 是 CentOS 8 最后一个公开归档的小版本,源地址必须带完整版本目录(
centos-vault/8.5.2111/...);若用了8/或latest/这类路径会报 404(实测踩坑)。改源后务必先dnf makecache确认两个仓库都能出元数据再继续。
2.4 安装基础工具与确认磁盘空间
dnf install -y wget
实测回显(输出节选):
Complete!
df -h / | tail -1
实测回显:
Filesystem Size Used Avail Use% Mounted on
overlay 786G 613G 139G 82% /
三、版本选型说明
CFEngine 官方版本线与 LTS 策略、社区版/企业版差异已在《CFEngine 3.27.2 Ubuntu 22.04 安装指南》第三章完整说明(3.27.2 为 3.27.x LTS 线最新版、官方标记 latestLTS,支持至 2028-12),此处不重复。CentOS 8 相关的选型要点只有一条:下载 el8 标签的 rpm 包。
el8 包的官方条目(取自 3.27.2 包清单):
curl -sL "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.27.2.json" | python3 -c "
import json,sys
d=json.load(sys.stdin)
for a in d['artifacts']['Binary packages']:
if a['Title']=='Red Hat / CentOS 8' and a['Arch']=='x86_64':
print(a['Title'], '|', a['SHA256'], '|', a['URL'])
"
实测回显:
Red Hat / CentOS 8 | 690a00eb8b94c16f4761fed11bd9415c8170f6a0717421d41ab88b7bc01669e9 | https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.2/agent_rhel8_x86_64/cfengine-community-3.27.2-1.el8.x86_64.rpm
解读:rpm 包命名规则为 cfengine-community-<版本>-1.el8.<架构>.rpm;下载路径中的平台目录是 agent_rhel8_x86_64(不是 agent_el8_x86_64,实测用错目录会得到 403 Forbidden)。
四、安装方案 A:官方 rpm 包 + dnf 安装(推荐主线)
官方对社区版的标准方式是下载单包安装。CentOS 8 上推荐用 dnf install(自动解决依赖,见 4.3 的依赖排障),纯 rpm 安装作为断网备用方案见第六章。
4.1 下载 rpm 包并校验
cd /tmp
wget https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.2/agent_rhel8_x86_64/cfengine-community-3.27.2-1.el8.x86_64.rpm
sha256sum cfengine-community-3.27.2-1.el8.x86_64.rpm
实测回显(wget 输出节选,实测首尾):
--2026-10-17 00:42:40-- https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.2/agent_rhel8_x86_64/cfengine-community-3.27.2-1.el8.x86_64.rpm
Resolving cfengine-package-repos.s3.amazonaws.com (cfengine-package-repos.s3.amazonaws.com)... 52.217.89.144, 16.15.207.55, 16.15.247.141, ...
Connecting to cfengine-package-repos.s3.amazonaws.com (cfengine-package-repos.s3.amazonaws.com)|52.217.89.144|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4708784 (4.5M) [application/x-redhat-package-manager]
Saving to: 'cfengine-community-3.27.2-1.el8.x86_64.rpm'
0K .......... .......... .......... .......... .......... 1% 197K 23s
4550K .......... .......... .......... .......... .......... 100% 187M=1.8s
2026-10-17 00:43:55 (2.55 MB/s) - 'cfengine-community-3.27.2-1.el8.x86_64.rpm' saved [4708784/4708784]
690a00eb8b94c16f4761fed11bd9415c8170f6a0717421d41ab88b7bc01669e9 cfengine-community-3.27.2-1.el8.x86_64.rpm
SHA256 与官方清单一致,包完整可信。
4.2 直接 rpm 安装的依赖报错(实测排障)
先用传统 rpm -ivh 安装会因依赖失败(保留此实录,帮助读者认识报错):
cd /tmp
rpm -ivh cfengine-community-3.27.2-1.el8.x86_64.rpm
实测回显:
warning: cfengine-community-3.27.2-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 9b920a5e: NOKEY
error: Failed dependencies:
selinux-policy >= 3.14.3 is needed by cfengine-community-3.27.2-1.el8.x86_64
解读:最小化 CentOS 8 没装 selinux-policy,rpm 不会自动解决依赖。处理方式两种:dnf install -y selinux-policy 后重试 rpm(第六章方案 B),或直接用 dnf 安装本包自动补依赖(4.3)。NOKEY 签名警告的说明见 10.2。
4.3 dnf 安装(自动解决依赖)
cd /tmp
dnf install -y ./cfengine-community-3.27.2-1.el8.x86_64.rpm
实测回显(dnf 事务清单,取自 dnf history info 3,输出节选):
Packages Altered:
Install checkpolicy-2.9-1.el8.x86_64 @BaseOS
Install libselinux-utils-2.9-5.el8.x86_64 @BaseOS
Install policycoreutils-2.9-16.el8.x86_64 @BaseOS
Install policycoreutils-python-utils-2.9-16.el8.noarch @BaseOS
Install python3-audit-3.0-0.17.20191104git1c2f876.el8.x86_64 @BaseOS
Install python3-libselinux-2.9-5.el8.x86_64 @BaseOS
Install python3-libsemanage-2.9-6.el8.x86_64 @BaseOS
Install python3-policycoreutils-2.9-16.el8.noarch @BaseOS
Install python3-setools-4.3.0-2.el8.x86_64 @BaseOS
Install rpm-plugin-selinux-4.14.3-19.el8.x86_64 @BaseOS
Install selinux-policy-3.14.3-80.el8_5.2.noarch @BaseOS
Install selinux-policy-minimum-3.14.3-80.el8_5.2.noarch @BaseOS
Install cfengine-community-3.27.2-1.el8.x86_64 @@commandline
Upgrade python3-rpm-4.14.3-19.el8.x86_64 @BaseOS
Upgraded python3-rpm-4.14.3-13.el8.x86_64 @@System
Upgrade rpm-4.14.3-19.el8.x86_64 @BaseOS
Upgraded rpm-4.14.3-13.el8.x86_64 @@System
Complete!
dnf 自动补齐了整个 SELinux 工具链(checkpolicy/policycoreutils/selinux-policy 等 12 个安装 + 4 个 rpm 组件升级)并完成安装。离线环境做方案 B 时,就是把这批依赖包一起拷进内网。
4.4 安装产物与目录结构
/var/cfengine/bin/cf-agent --version
ls /var/cfengine/
实测回显:
CFEngine Core 3.27.2
bin
inputs
lastseen
lib
masterfiles
modules
outputs
ppkeys
randseed
reports
selinux
share
state
与 Ubuntu 相比多了一个 selinux/ 目录:rpm 包附带 CFEngine 的 SELinux 策略模块(cfengine-enterprise.pp 等),安装事务中会尝试导入系统 SELinux 策略库。其余目录作用与《CFEngine 3.27.2 Ubuntu 22.04 安装指南》4.3 节的表格一致,此处不重复。
五、自举与 systemd 服务验证
5.1 自举(bootstrap)
单机场景自举到自己:
/var/cfengine/bin/cf-agent --bootstrap 127.0.0.1
实测回显:
warning: Bootstrapping to loopback interface (localhost), other hosts will not be able to bootstrap to this server
R: Bootstrapping from host '127.0.0.1' via built-in policy '/var/cfengine/inputs/failsafe.cf'
R: This host assumes the role of policy server
R: Updated local policy from policy server
R: Triggered an initial run of the policy
notice: Bootstrap to '127.0.0.1' completed successfully!
自举成功,Masterfiles 已同步到 inputs。逐行解读见《CFEngine 3.27.2 Ubuntu 22.04 安装指南》4.4 节。
⚠️ 注意:与 Ubuntu 包不同,el8 包的 rpm 安装脚本没有在安装时 enable 服务(
systemctl list-unit-files的 vendor preset 列为 disabled),且上述自举回显中也没有R: Restarted systemd unit cfengine3行——CentOS 8 上自举完成后服务不会自动拉起,必须手动启动(见 5.2)。
5.2 启动服务(CentOS 8 必做)
systemctl start cfengine3
验证伞形单元与三个子单元(systemctl 每次只操作一个单元):
systemctl is-active cfengine3
systemctl is-active cf-serverd
systemctl is-active cf-execd
systemctl is-active cf-monitord
实测回显:
active
active
active
active
5.3 单元清单与开机自启
systemctl list-unit-files | grep -E "^cf"
实测回显:
cf-execd.service disabled
cf-monitord.service disabled
cf-serverd.service disabled
cfengine3.service enabled
解读:与 Ubuntu 输出的差异是 CentOS 的 list-unit-files 只有两列(无 vendor preset 列);cfengine3.service 已 enabled(开机自启),三个子单元 disabled 是设计如此,由伞形单元通过 Wants= 拉起。伞形单元定义位置在 /usr/lib/systemd/system/cfengine3.service(Ubuntu 上是 /lib/systemd/system,二者为同一文件的两种规范化路径):
systemctl cat cfengine3.service | head -14
实测回显:
# /usr/lib/systemd/system/cfengine3.service
[Unit]
Description=CFEngine 3 umbrella service
Documentation=https://docs.cfengine.com/ https://northerntech.atlassian.net
After=syslog.target
# Try to start all the sub-services. 'Wants' is fault-tolerant so if some are
# missing or impossible to start, no big deal.
Wants=cf-serverd.service
Wants=cf-execd.service
Wants=cf-monitord.service
Wants=cf-postgres.service
Wants=cf-php-fpm.service
Wants=cf-apache.service
5.4 端口监听与进程验证
ss -tlnp | grep 5308
实测回显:
LISTEN 0 128 *:5308 *:* users:(("cf-serverd",pid=1914,fd=5))
ps aux | grep -E "cf-(serverd|execd|monitord)" | grep -v grep
实测回显:
root 1914 0.0 0.0 128544 14424 ? Ss 00:28 0:00 /var/cfengine/bin/cf-serverd --no-fork
root 1916 0.0 0.0 128320 14224 ? Ss 00:28 0:00 /var/cfengine/bin/cf-execd --no-fork
root 1917 0.1 0.0 128760 14952 ? Ss 00:28 0:00 /var/cfengine/bin/cf-monitord --no-fork
5.5 调度与幂等验证
journalctl -u cf-execd --no-pager | tail -3
实测回显:
Oct 17 00:21:42 6bdf7dc677dc systemd[1]: cf-execd.service: Succeeded.
Oct 17 00:21:42 6bdf7dc677dc systemd[1]: Stopped CFEngine Execution Scheduler.
Oct 17 00:28:42 6bdf7dc677dc systemd[1]: Started CFEngine Execution Scheduler.
/var/cfengine/bin/cf-agent -KI
echo $?
实测回显(策略已收敛,无变更输出;退出码 0):
0
cf-execd 按 Min00/Min05/.../Min55 节奏每 5 分钟自动执行一次 cf-agent;R: 类策略输出随自带的默认策略不会出现,等部署自定义策略后可见(见《CFEngine 3.27.2 快速入门与策略编写示例》)。
六、安装方案 B:离线 rpm 安装(断网备用)
内网隔离机器无法 dnf 在线补依赖时的方案:把 selinux-policy 等依赖包与 CFEngine rpm 一起拷入内网,手动补齐依赖后用纯 rpm 安装。依赖包可在可联网的同版本 CentOS 8 机器上用 dnf download --resolve cfengine-community 或 yum install --downloadonly 预先取得(至少需要 selinux-policy、selinux-policy-minimum、rpm-plugin-selinux、python3-setools,版本以 dnf install 输出为准,见 4.3 实测)。
依赖就位后安装:
cd /tmp
rpm -ivh cfengine-community-3.27.2-1.el8.x86_64.rpm
实测回显(依赖已满足环境):
warning: cfengine-community-3.27.2-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 9b920a5e: NOKEY
Verifying... ########################################
Preparing... ########################################
Updating / installing...
cfengine-community-3.27.2-1.el8 ########################################
Failed to resolve booleanif statement at /var/lib/selinux/targeted/tmp/modules/400/cfengine-enterprise/cil:869
semodule: Failed!
warning! semodule import failed, examine /var/log/CFE*log and consider installing selinux-policy-devel package and rebuilding policy with: cd /var/cfengine/selinux make -f /usr/share/selinux/devel/Makefile -j1 semodule -n -i /var/cfengine/selinux/cfengine-enterprise.pp and then restarting services with systemctl restart cfengine3
rpm -q cfengine-community
/var/cfengine/bin/cf-agent --version
实测回显:
cfengine-community-3.27.2-1.el8.x86_64
CFEngine Core 3.27.2
安装成功、agent 可用。事务末尾的 semodule: Failed! 警告说明与处置见 10.3。
七、方案对比与选择建议
| 维度 | 方案 A:dnf install 本包 | 方案 B:rpm -ivh 离线安装 |
|---|---|---|
| 前置网络 | 需要软件源可达(或本地源) | 完全断网,依赖包需预先拷入 |
| 依赖处理 | 自动解析安装 | 手动预置依赖包 |
| 额外动作 | 无 | 需自行处理 SELinux 模块警告 |
| 适用场景 | 常规联网服务器 | 内网隔离、批量预分发 |
选择建议:能联网(或有内网源)一律用方案 A;断网环境用方案 B 并把依赖包一起打包下发。两种方式安装出的 /var/cfengine 结构完全一致,后续自举、运行无差别。
八、安装后基础验证
8.1 主机身份与密钥
自举过程中 cf-key 生成了本机密钥对:
ls /var/cfengine/ppkeys/
实测回显:
localhost.priv
localhost.pub
root-MD5=be00e7fb23e1744a937805c99f60e6b0.pub
💡 说明:密钥文件命名规律为
root-MD5=<公钥摘要>.pub,localhost.priv/localhost.pub是本机身份密钥。密钥与信任机制详见《CFEngine 3.27.2 进阶实战与运维》。
8.2 数据目录
安装占约 20 MB,策略、密钥、状态全部集中在 /var/cfengine:
du -sh /var/cfengine
实测回显:
20M /var/cfengine
九、升级与降级
9.1 升级
rpm 升级用 rpm -Uvh(U=升级/安装,v=详细,h=进度)。已安装 3.27.2 时对同版本包执行会提示已安装(实测):
cd /tmp
rpm -Uvh cfengine-community-3.27.2-1.el8.x86_64.rpm
实测回显:
warning: cfengine-community-3.27.2-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 9b920a5e: NOKEY
Verifying... ########################################
Preparing... ########################################
package cfengine-community-3.27.2-1.el8.x86_64 is already installed
正式升级时,下载新版本 rpm(URL 模式同第三章,目录 Community-<新版本>/agent_rhel8_x86_64/)后执行同样的 rpm -Uvh <新版本>.rpm 即可,配置与 /var/cfengine 数据保留;升级后 systemctl restart cfengine3 使新二进制生效。
9.2 降级
rpm 用 --oldpackage 强制安装更低版本(实测从 3.27.2 降到 3.27.1):
cd /tmp
wget -q https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.1/agent_rhel8_x86_64/cfengine-community-3.27.1-1.el8.x86_64.rpm
rpm -Uvh --oldpackage cfengine-community-3.27.1-1.el8.x86_64.rpm
实测回显(输出节选):
warning: cfengine-community-3.27.1-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 9b920a5e: NOKEY
Verifying... ########################################
Preparing... ########################################
Updating / installing...
cfengine-community-3.27.1-1.el8 ########################################
Failed to resolve booleanif statement at /var/lib/selinux/targeted/tmp/modules/400/cfengine-enterprise/cil:869
semodule: Failed!
warning! semodule import failed, examine /var/log/CFE*log and consider installing selinux-policy-devel package and rebuilding policy with: cd /var/cfengine/selinux make -f /usr/share/selinux/devel/Makefile -j1 semodule -n -i /var/cfengine/selinux/cfengine-enterprise.pp and then restarting services with systemctl restart cfengine3
Cleaning up / removing...
cfengine-community-3.27.2-1.el8 ########################################
rpm -q cfengine-community
实测回显:
cfengine-community-3.27.1-1.el8.x86_64
降级前备份 /var/cfengine/masterfiles 与 /var/cfengine/inputs(新版策略语法可能旧 agent 不识别)。实测演示后升级回 3.27.2:
rpm -Uvh cfengine-community-3.27.2-1.el8.x86_64.rpm
实测回显(输出节选):
Updating / installing...
cfengine-community-3.27.2-1.el8 ########################################
Cleaning up / removing...
cfengine-community-3.27.1-1.el8 ########################################
十、常见问题(FAQ)
10.1 dnf makecache 报 Could not resolve host: mirrorlist.centos.org
CentOS 8 EOL 后的必踩坑,完整排障实录见第二章 2.1–2.3:注释 mirrorlist、baseurl 指向 centos-vault/8.5.2111、dnf makecache 验证。
10.2 rpm 安装报 NOKEY 签名警告
现象:每次 rpm 事务都出现 warning: ... Header V4 RSA/SHA256 Signature, key ID 9b920a5e: NOKEY。
定位:rpm 包带了官方 GPG 签名,但系统钥匙环里没有导入对应公钥;仅是警告,不影响安装。
解决:因下载时已用官方清单的 SHA256 校验过包完整性(见 4.1),警告可安全忽略;要消除警告可从 CFEngine 官网获取 GPG 公钥导入 rpm --import。
10.3 安装事务末尾 semodule: Failed! 警告
现象:rpm 事务末尾出现:
Failed to resolve booleanif statement at /var/lib/selinux/targeted/tmp/modules/400/cfengine-enterprise/cil:869
semodule: Failed!
warning! semodule import failed, examine /var/log/CFE*log and consider installing selinux-policy-devel package and rebuilding policy with: cd /var/cfengine/selinux make -f /usr/share/selinux/devel/Makefile -j1 semodule -n -i /var/cfengine/selinux/cfengine-enterprise.pp and then restarting services with systemctl restart cfengine3
定位:rpm 附带的 SELinux 策略模块 cfengine-enterprise.pp 在导入系统 SELinux 库时,booleanif 语句与当前 selinux-policy 版本的编译规则不兼容而失败。该模块服务于 SELinux 强制模式下的企业版进程约束;cf-agent/cf-serverd 等核心进程在 SELinux 关闭(Enforcing=false)或 minimum 策略下不受影响。
解决:功能验证可忽略此警告(实测服务全部正常启动、策略正常执行);生产环境启用 SELinux Enforcing 的机器,按警告提示安装 selinux-policy-devel 并重建模块:
dnf install -y selinux-policy-devel
cd /var/cfengine/selinux && make -f /usr/share/selinux/devel/Makefile -j1
semodule -n -i /var/cfengine/selinux/cfengine-enterprise.pp
systemctl restart cfengine3
10.4 自举后服务没有运行
现象:--bootstrap 127.0.0.1 显示成功,但 systemctl is-active cfengine3 为 inactive、5308 无监听。
定位:el8 包安装脚本不在安装时 enable 子服务,自举回显中也没有 R: Restarted systemd unit cfengine3 行(对照 Ubuntu 包的行为差异,见 5.1 ⚠️)。
解决:自举后手动执行 systemctl start cfengine3,再用 5.2–5.4 的命令逐项验证 active 与 5308 监听(实测一次通过)。
10.5 用错了下载目录得到 403 Forbidden
现象:wget 地址写成 .../Community-3.27.2/agent_el8_x86_64/cfengine-community-3.27.2-1.el8.x86_64.rpm 时返回 403。
定位与解决:S3 包仓库的平台目录与包名标签不一致——包名是 el8,目录是 agent_rhel8_x86_64。一律以官方 3.27.2.json 清单里的 URL 为准(见第三章),不要手拼路径。
十一、卸载与清理
11.1 卸载软件包
rpm -e cfengine-community
实测回显(rpm -e 静默成功,退出码 0):
(无输出)
卸载后验证:服务停止、数据保留:
systemctl is-active cfengine3
ls /var/cfengine/ | head -6
rpm -q cfengine-community
ps aux | grep cf- | grep -v grep | wc -l
实测回显:
inactive
backups
bin
bootstrap_id.dat
cfagent.6bdf7dc677dc.log
inputs
lastseen
package cfengine-community is not installed
0
rpm -e 不删除 /var/cfengine(策略、密钥、状态数据全部保留,便于重装恢复),也不需要手动 stop(卸载脚本会停止服务)。
11.2 彻底清除
确认无需保留旧策略与数据后删除数据目录:
rm -rf /var/cfengine
ls /var/cfengine
实测回显:
ls: cannot access '/var/cfengine': No such file or directory
重装后再次使用前记得重新自举(/var/cfengine/bin/cf-agent --bootstrap 127.0.0.1)。
十二、参考链接
- CFEngine 官方下载页:https://cfengine.com/downloads/
- 官方安装文档(Installing Community):https://docs.cfengine.com/latest/getting-started/01-installing-cfengine/general-installation/installation-community/
- 3.27.2 包清单(含 el8 rpm SHA256):https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.27.2.json
- 3.27.1 包清单(含 el8 rpm SHA256):https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.27.1.json
- CentOS 8 归档仓库(TUNA vault):https://mirrors.tuna.tsinghua.edu.cn/centos-vault/
- 源码仓库:https://github.com/cfengine/core
- 同系列文档:《CFEngine 3.27.2 Ubuntu 22.04 安装指南》《CFEngine 3.27.2 快速入门与策略编写示例》《CFEngine 3.27.2 配置参数详解》《CFEngine 3.27.2 进阶实战与运维》