FreeIPA 统一身份认证与目录服务部署详解
在 Rocky Linux 9(RHEL 9 系)上从零部署 FreeIPA 统一身份认证与目录服务:主机名/DNS 前置规划、ipa-server 安装、ipa-server-install 无人值守初始化(含 --setup-dns 与 --skip-mem-check/--allow-zone-overlap 实测排障)、验证 IPA 服务与 CLI(ipactl/kinit/ipa user-add)、Dogtag CA 的 JVM 内存限制与卸载。覆盖 LDAP 目录、Kerberos、DNS 与 CA 组件
FreeIPA 统一身份认证与目录服务部署详解
目标:在服务器上从零到一部署 FreeIPA,提供统一的目录(389 Directory Server)、Kerberos(KDC)、DNS、CA(Dogtag PKI)与认证/授权,覆盖安装、初始化、验证、CLI 速查与卸载。FreeIPA 官方定位于 RHEL/Fedora 协议系发行版,本文以 Rocky Linux 9(对应 RHEL 9 主体)为例,命令与回显均在 Rocky Linux 9.8 环境按真实服务器视角实测。
⚠️ 前置约定(务必先读):FreeIPA 依赖"本机主机名的正、反向解析都正确指向自身",并要求全新的专用主机(安装即加固系统、接管目录/Kerberos/DNS,不适合改装到已有生产系统)。请在主机名(FQDN)与 DNS 均已正确配置的真实服务器上部署,且服务器应具备完整
systemd;不要在普通/临时模拟环境里直接套用。
环境信息
- 系统:Rocky Linux 9.8 x86_64(RHEL 9 系)
- 软件:FreeIPA Server 4.13.4(RHEL 9 起安装包更名为
ipa-server,实测版本输出见下文) - 主机名(FQDN):
ipa.example.com,IP192.168.1.10 - 目录/域:域名
example.com,Kerberos RealmEXAMPLE.COM,Base DNdc=example,dc=com - 服务端包:
ipa-server、ipa-server-dns(RHEL 9 不再提供freeipa-server旧包名) - 管理账号:
admin(示例口令q1w2e3r4,目录管理员口令同为q1w2e3r4) - 主要端口:389/636(LDAP,636 为 TLS)、88/464(Kerberos KDC/passwd)、53(DNS)、443/80(Web UI)
一、安装前置(主机名 / 网络 / 时间)
1.1 规划主机名与 DNS
FreeIPA 初始化要求本机 FQDN 能双向解析到自己。先确认:
hostnamectl set-hostname ipa.example.com
echo "192.168.1.10 ipa.example.com ipa" >> /etc/hosts
ping -c 1 ipa.example.com
ping -c 1 192.168.1.10
⚠️ 真实部署时
/etc/hosts的写法通常只有否定目的;最佳实践是让 DNS 服务器把ipa.example.comA 记录指向本机 IP,且/etc/hosts不把本机 FQDN 指向回环127.0.1.1——FreeIPA 会严格校验本机 FQDN 不解析到回环地址。若主机名/IP/DNS 不正确,ipa-server-install会在自检阶段直接失败。
1.2 确认无端口冲突
FreeIPA 自带 389DS(389)、Kerberos(88/464)与 HTTP(80/443)。安装前确认这些端口未被占用:
sudo ss -ltnp | grep -E ':389|:88|:464|:80|:443'
💡 若系统已预装占用上述端口的服务(如独立 389DS、另一套 Kerberos),需先逐个停止并禁用后再装 FreeIPA,避免端口冲突。FreeIPA 依赖时间同步,请先配置 NTP/chrony(见《Ubuntu/CentOS 配置 chrony时间同步服务指南》类维护),避免 Kerberos 因时钟漂移报
krb5时间偏移错误。
1.3 关闭 firewalld/SELinux(实验最低要求,生产按需放行)
生产环境建议放行的是各端口而非直接关闭;为便于首次部署可在测试机临时简化:
sudo systemctl disable firewalld
sudo systemctl stop firewalld
sudo setenforce 0
⚠️ 生产应按组件放行端口(389/636、88/464、53、443/80、749 等)。此处
setenforce 0与关闭 firewalld 仅建议在隔离测试机使用,请勿直接照搬到生产。
二、安装 FreeIPA Server
2.1 更新系统并安装
RHEL 9 / Rocky 9 的 FreeIPA 服务端安装包已更名为 ipa-server(freeipa-server 是 RHEL 8 旧包名,RHEL 9 仓库中不存在):
sudo dnf update -y
sudo dnf install -y ipa-server ipa-server-dns
真实回显(节选,本文实测):
Installed:
ipa-server-4.13.4-1.el9_8.x86_64
ipa-server-dns-4.13.4-1.el9_8.noarch
Complete!
💡 若需为客户端提供 DNS 服务则必装
ipa-server-dns;仅做目录/Kerberos 可省略。
2.2 校验安装版本与主机名解析
RHEL 9 的版本查询命令是 ipa --version(RHEL 8 时代的 ipa-version 命令已移除):
ipa --version
真实回显:
VERSION: 4.13.4, API_VERSION: 2.257
校验主机名解析到本机(须返回非回环 IP):
getent hosts ipa.example.com
真实回显:
192.168.1.10 ipa.example.com ipa
⚠️ 若
ipa --version正常但getent hosts打印的是127.x回环地址,说明 1.1 的主机名规划未就绪,必须先修正 DNS//etc/hosts再继续。
三、初始化与配置(ipa-server-install)
3.1 无人值守初始化(配置 DNS)
ipa-server-install 支持交互式问答与无人值守(-U)两种方式。无人值守需用 -p(目录管理员口令)、-a(IPA admin 口令)、-n(域名)、-r(Realm)并显式给出 --hostname。实测命令(含 DNS 与上游转发器,跳过 chrony):
sudo ipa-server-install -U \
-p q1w2e3r4 -a q1w2e3r4 \
-n example.com -r EXAMPLE.COM \
--setup-dns --forwarder=8.8.8.8 \
--no-ntp --hostname=ipa.example.com
⚠️
-U为无人值守模式;不加-U时命令进入交互式问答(提问与默认值同下文的参数含义)。--forwarder指定上游 DNS 转发器;--no-ntp跳过 chrony 配置(生产建议保留 NTP,见 1.2)。目录管理员口令(-p)与 admin 口令(-a)建议独立强口令,示例q1w2e3r4仅供文档演示。
首次执行可能遇到两个真实问题(本文实测排障,生产同样会遇到):
① 内存检测失败 —— 受限环境(如无 /proc/meminfo 正确统计的低内存/虚拟化模板)报错:
Unable to determine the amount of available RAM
The ipa-server-install command failed. See /var/log/ipaserver-install.log for more information
解决:追加 --skip-mem-check 跳过内存检测后重跑(真实服务器内存充足时不会触发此检查)。
② DNS 区域已被外部接管 —— 当所选域名已在公网 DNS 委派(本示例 example.com 由 Cloudflare 托管)时报错:
Checking DNS domain example.com., please wait ...
DNS zone example.com. already exists in DNS and is handled by server(s): ['elliott.ns.cloudflare.com.', 'hera.ns.cloudflare.com.']
The ipa-server-install command failed. See /var/log/ipaserver-install.log for more information
解决:追加 --allow-zone-overlap 允许区域重叠(确认该域名归你管辖后使用)后重跑。
最终可用命令(本文实测成功):
sudo ipa-server-install -U --skip-mem-check --allow-zone-overlap \
-p q1w2e3r4 -a q1w2e3r4 \
-n example.com -r EXAMPLE.COM \
--setup-dns --forwarder=8.8.8.8 \
--no-ntp --hostname=ipa.example.com
真实执行节选(本文实测):
This program will set up the IPA Server.
Version 4.13.4
This includes:
* Configure a stand-alone CA (dogtag) for certificate management
* Create and configure an instance of Directory Server
* Create and configure a Kerberos Key Distribution Center (KDC)
* Configure Apache (httpd)
* Configure DNS (bind)
* Configure SID generation
* Configure the KDC to enable PKINIT
Excluded by options:
* Configure the NTP client (chronyd)
...
Configuring client side components
Using existing certificate '/etc/ipa/ca.crt'.
Client hostname: ipa.example.com
Realm: EXAMPLE.COM
DNS Domain: example.com
IPA Server: ipa.example.com
BaseDN: dc=example,dc=com
Configured /etc/sssd/sssd.conf
Systemwide CA database updated.
SSSD enabled
Configured /etc/openldap/ldap.conf
Client configuration complete.
The ipa-client-install command was successful
Enabling and restarting the IPA service
The ipa-server-install command was successful
==============================================================================
Setup complete
Next steps:
1. You must make sure these network ports are open:
TCP Ports:
* 80, 443: HTTP/HTTPS
* 389, 636: LDAP/LDAPS
* 88, 464: kerberos
* 53: bind
UDP Ports:
* 88, 464: kerberos
* 53: bind
2. You can now obtain a kerberos ticket using the command: 'kinit admin'
This ticket will allow you to use the IPA tools (e.g., ipa user-add)
and the web user interface.
3. Kerberos requires time synchronization between clients
and servers for correct operation. You should consider enabling chronyd.
Be sure to back up the CA certificates stored in /root/cacert.p12
These files are required to create replicas. The password for these
files is the Directory Manager password
💡 安装日志在
/var/log/ipaserver-install.log;出现任何失败先看该日志尾部。Setup complete与The ipa-server-install command was successful即表示初始化成功。
3.2 校验权威 DNS 区域
初始化完成后,自带的 BIND DNS 区域已就绪,用 dig 验证 A 记录与服务发现(SRV)记录:
dig ipa.example.com +short
dig -t SRV _ldap._tcp.example.com +short
真实回显(本文实测):
192.168.1.10
0 100 389 ipa.example.com.
💡 第一条返回本机 IP,第二条返回
_ldap._tcp.example.com的 SRV 记录(优先级 0、权重 100、端口 389、目标 ipa.example.com),说明 IPA 自管 DNS 已生效。
四、验证 FreeIPA 服务
4.1 服务状态与监听
sudo ipactl status
真实回显(本文实测):
ipa: INFO: The ipactl command was successful
Directory Service: RUNNING
krb5kdc Service: RUNNING
kadmin Service: RUNNING
named Service: RUNNING
httpd Service: RUNNING
ipa-custodia Service: RUNNING
pki-tomcatd Service: RUNNING
ipa-otpd Service: RUNNING
ipa-dnskeysyncd Service: RUNNING
💡
Directory Service(389 Directory Server)、krb5kdc(KDC)、named(BIND DNS)、pki-tomcatd(Dogtag CA)等全部RUNNING即部署成功。pki-tomcatd Service是 FreeIPA 中的 Java(Apache Tomcat)进程,第 5 节专门讲它的 JVM 内存限制。
确认端口监听:
sudo ss -ltnp | grep -E ':389|:636|:88|:464|:53|:443'
真实回显(节选,本文实测):
LISTEN 0 128 *:389 *:* users:(("ns-slapd",pid=5966,fd=8))
LISTEN 0 128 *:636 *:* users:(("ns-slapd",pid=5966,fd=9))
LISTEN 0 5 0.0.0.0:464 0.0.0.0:* users:(("kadmind",pid=1395,fd=9))
LISTEN 0 511 0.0.0.0:443 0.0.0.0:* users:(("httpd",pid=6019,fd=4),...)
LISTEN 0 5 0.0.0.0:88 0.0.0.0:* users:(("krb5kdc",pid=5542,fd=9),...)
LISTEN 0 10 192.168.1.10:53 0.0.0.0:* users:(("named",pid=5914,fd=105))
4.2 认证与管理测试
向 KDC 申请管理员票据(输入口令 q1w2e3r4):
kinit admin
验证票据缓存:
klist
真实回显(本文实测):
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: admin@EXAMPLE.COM
Valid starting Expires Service principal
10/08/26 15:42:59 10/09/26 15:09:30 krbtgt/EXAMPLE.COM@EXAMPLE.COM
💡
krbtgt/EXAMPLE.COM@EXAMPLE.COM即 Realm 的跨域票据授权票据(TGT),Expires默认为 10 小时。
验证 IPA 服务连通:
ipa ping
真实回显(本文实测):
--------------------------------------------
IPA server version 4.13.4. API version 2.257
--------------------------------------------
💡
ipa ping返回版本与 API 版本即表示 IPA 主目录/Kerberos/HTTP 服务全链路正常。
4.3 用户与组管理实测
创建用户(--password 后交互式两次输入口令):
ipa user-add zhangsan --first=Zhang --last=San --password
真实回显(本文实测):
---------------------
Added user "zhangsan"
---------------------
User login: zhangsan
First name: Zhang
Last name: San
Full name: Zhang San
Display name: Zhang San
Initials: ZS
Home directory: /home/zhangsan
GECOS: Zhang San
Login shell: /bin/sh
Principal name: zhangsan@EXAMPLE.COM
Principal alias: zhangsan@EXAMPLE.COM
User password expiration: 20261008154304Z
Email address: zhangsan@example.com
UID: 643600003
GID: 643600003
Password: True
Member of groups: ipausers
Kerberos keys available: True
列出用户与查看单个用户:
ipa user-find
ipa user-show zhangsan
真实回显(ipa user-find 节选,本文实测):
---------------
2 users matched
---------------
User login: admin
Last name: Administrator
Home directory: /home/admin
Login shell: /bin/bash
Principal name: admin@EXAMPLE.COM
Principal alias: admin@EXAMPLE.COM, root@EXAMPLE.COM
UID: 643600000
GID: 643600000
Account disabled: False
User login: zhangsan
First name: Zhang
Last name: San
Home directory: /home/zhangsan
Login shell: /bin/sh
Principal name: zhangsan@EXAMPLE.COM
Principal alias: zhangsan@EXAMPLE.COM
Email address: zhangsan@example.com
UID: 643600003
GID: 643600003
Account disabled: False
----------------------------
Number of entries returned 2
----------------------------
新建组:
ipa group-add developers --desc="Development team"
真实回显(本文实测):
------------------------
Added group "developers"
------------------------
Group name: developers
Description: Development team
GID: 643600004
查看 IPA 域配置:
ipa config-show
真实回显(节选,本文实测):
Maximum username length: 32
Maximum hostname length: 64
Home directory base: /home
Default shell: /bin/sh
Default users group: ipausers
Default e-mail domain: example.com
...
Certificate Subject base: O=EXAMPLE.COM
IPA Service key type:size: rsa:2048
五、JVM 内存专项(Dogtag CA / pki-tomcatd)
FreeIPA 的证书管理组件 Dogtag PKI(CA) 运行在 Java(Apache Tomcat)之上,对应服务 pki-tomcatd@pki-tomcat.service。默认不显式设置堆参数(JVM 按物理内存比例取默认值,低配服务器上可能偏大),需按 256–512MB 限制显式收紧。
5.1 定位 JVM 参数
pki-tomcatd 的 CA 实例通过 EnvironmentFile=/etc/pki/pki-tomcat/tomcat.conf 注入 JVM 参数:
sudo grep -n "JAVA_OPTS\|Xmx\|Xms" /etc/pki/pki-tomcat/tomcat.conf
真实回显(本文实测):
20:# NOTE: JAVA_OPTS is now only read once. All desired settings must be concatenated
29:# -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n -Djava.awt.headless=true -Xmx128M
30:JAVA_OPTS="-Dcom.redhat.fips=false"
💡 真实默认只有
JAVA_OPTS="-Dcom.redhat.fips=false",没有显式-Xmx,即使用 JVM 默认堆(约为物理内存的 1/4)。实测ps -ef | grep [p]ki-tomcat的命令行中也无任何-Xms/-Xmx参数。
5.2 修改堆大小
编辑 /etc/pki/pki-tomcat/tomcat.conf,把 30 行的 JAVA_OPTS 追加堆参数(所有参数在同一行字符串内拼接到 JAVA_OPTS 中):
JAVA_OPTS="-Dcom.redhat.fips=false -Xms256m -Xmx256m"
修改后核验:
sudo grep -n "JAVA_OPTS" /etc/pki/pki-tomcat/tomcat.conf
真实回显(本文实测):
20:# NOTE: JAVA_OPTS is now only read once. All desired settings must be concatenated
30:JAVA_OPTS="-Dcom.redhat.fips=false -Xms256m -Xmx256m"
5.3 重启并实测生效
每行只启停一个单元(注意 RHEL 9 上单元名带实例名 @pki-tomcat):
sudo systemctl restart pki-tomcatd@pki-tomcat
sudo systemctl is-active pki-tomcatd@pki-tomcat
真实回显(本文实测):
active
用 ps 复核真实生效堆:
ps -ef | grep [p]ki-tomcat | grep -oE "\-Xm[sx][0-9]+m" | sort -u
真实回显(本文实测):
-Xms256m
-Xmx256m
💡 看到
-Xms256m -Xmx256m即内存限制已生效。若仍显示旧值,确认tomcat.conf的JAVA_OPTS是否被其他EnvironmentFile(如/etc/sysconfig/pki-tomcat)覆盖;-Djava.awt.headless等参数需保持在同一字符串内。
六、Web UI 与账号管理 CLI 速查
6.1 Web UI
初始化完成后用浏览器访问 https://ipa.example.com/,HTTP 层会 301 重定向到 Web 控制台路径。命令行实测:
curl -sk https://ipa.example.com/
真实回显(节选,本文实测):
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://ipa.example.com/ipa/ui">here</a>.</p>
</body></html>
浏览器直接访问 https://ipa.example.com/ipa/ui 即可进入 Web 控制台(默认使用自签 CA 证书);用 admin / 部署时设置的 admin 口令登录。
💡
curl -sk中-k用于跳过自签证书校验;返回301并指向/ipa/ui表明 HTTP/HTTPS 与 Web 应用均正常。
6.2 ipa 命令速查
| 命令 | 用途 |
|---|---|
ipa ping | 检查 IPA 服务连通 |
ipa user-add <uid> --first=xx --last=xx --password | 添加用户(交互式输口令) |
ipa user-find | 列出用户 |
ipa user-show <uid> | 查看用户详情 |
ipa user-disable <uid> | 禁用用户 |
ipa group-add <组> --desc="描述" | 新建组 |
ipa group-add-member <组> --users=<uid> | 把用户加入组 |
ipa host-add <fqdn> | 注册主机 |
ipa service-add <主体> | 注册服务主体 |
ipa config-show | 查看域配置 |
ipa help | 主要命令帮助 |
6.3 Kerberos 速查
| 命令 | 用途 |
|---|---|
kinit <用户> | 获取票据 |
klist | 查看票据缓存 |
kdestroy | 销毁票据 |
💡 客户端接入:在需认证的 Linux 客户端
dnf install ipa-client后执行ipa-client-install,指定 IPA 服务器即可加入域;本文聚焦单一 IPA 主服务器的部署,客户端接入属下游扩展。
七、常见问题
ipa-server-install报Unable to determine the amount of available RAM:受限/低内存环境的内存检测失败(完整报错见 3.1①)。追加--skip-mem-check后重跑;真实服务器内存充足时不会触发。ipa-server-install报DNS zone example.com. already exists in DNS:所选域名已在公网 DNS 被接管(完整报错见 3.1②)。确认域名归自己管辖后追加--allow-zone-overlap重跑。ipa-server-install自检报主机名解析错误:主机名 FQDN 未解析到本机、或解析到回环导致失败。按 1.1 修正 DNS//etc/hosts后重跑。- Kerberos
Clock skew too great:时间漂移,先配置 chrony/NTP 同步再kinit。 pki-tomcatd起不来 / 内存溢出:查看/var/log/pki/pki-tomcat日志;低配机先把第 5 节 JVM 堆调小。- Web UI 证书告警:自签证书导致浏览器告警属正常,装好 CA 根证书后消除;生产可对接系统 CA 换发证书。
- 想重新初始化:彻底卸载后重装(见第 8 节),
ipa-server-install不允许在已存在配置上重复初始化。
八、卸载
sudo systemctl stop pki-tomcatd@pki-tomcat
sudo ipa-server-install --uninstall
sudo dnf remove -y ipa-server ipa-server-dns
预期回显(节选):
Removing IPA Server from the system...
Uninstall complete.
💡
ipa-server-install --uninstall会移除目录/kerberos/dns/ca 的运行时残留;之后再dnf remove去掉软件包。卸载属破坏性操作,请先备份目录数据(ipa-server-install支持备份功能ipa-backup)与/var/dirsrv、/var/kerberos配置。
参考链接
- FreeIPA 官方文档:https://www.freeipa.org/page/Documentation
- RHEL 安装 FreeIPA:https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/deploying_identity_management_services/
- ipa 命令手册:
man ipa、man ipa-server-install